-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
19 lines (16 loc) · 792 Bytes
/
script.js
File metadata and controls
19 lines (16 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Select elements
const totalAmountInput = document.getElementById('total-amount');
const numPeopleInput = document.getElementById('num-people');
const calculateBtn = document.getElementById('calculate-btn');
const resultDisplay = document.getElementById('result');
// Calculate and display the split amount
calculateBtn.addEventListener('click', () => {
const totalAmount = parseFloat(totalAmountInput.value);
const numPeople = parseInt(numPeopleInput.value);
if (isNaN(totalAmount) || isNaN(numPeople) || totalAmount <= 0 || numPeople <= 0) {
alert('Please enter valid values for both fields.');
return;
}
const splitAmount = (totalAmount / numPeople).toFixed(2);
resultDisplay.innerHTML = `Each person owes: <span>₹${splitAmount}</span>`;
});