-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (37 loc) · 1.31 KB
/
Copy pathscript.js
File metadata and controls
44 lines (37 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const submit = document.getElementById("submit");
const amount = document.getElementById("amt");
const tip = document.getElementById("tip");
const amt_display = document.getElementById("amt_display");
const incre = document.getElementById("incre");
const decre = document.getElementById("decre");
const people = document.getElementById("people");
let numberOfPeople = 1;
submit.onclick = () => {
totalAmt();
(amount.value === "" || tip.value === "") ? alert("Please, Enter Some Amount and Tip") : alert("Thank You" + "\n" + "Your Tip is " + tip.value + "%" + "\n" + "Your Total Amount is " + amt_display.innerHTML + "\n" + "Number of People is " + numberOfPeople);
};
incre.onclick = () => {
increment();
};
decre.onclick = () => {
decrement();
};
const totalAmt = () => {
let amt = Number(amount.value);
let tipped = Number(tip.value);
let total = Number(amt + amt * (tipped / 100));
let perPerson = total / numberOfPeople;
amt_display.innerHTML = `₹${perPerson.toFixed(2)}`;
//alert(`total amount with tip in percentage is ${total}`);
};
const increment = () => {
numberOfPeople++;
people.innerHTML = numberOfPeople;
totalAmt();
};
const decrement = () => {
if (numberOfPeople === 1) return alert("Minimum number of people is 1");
numberOfPeople--;
people.innerHTML = numberOfPeople;
totalAmt();
};