-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
75 lines (55 loc) · 2.1 KB
/
script.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function changeImage(anything) {
document.getElementById('slider').src = anything;
}
function ToggleMenu() {
const menuToggle = document.querySelector('.menuToggle');
const navigation = document.querySelector('.navigation');
menuToggle.classList.toggle('active');
navigation.classList.toggle('active');
}
// for i_food.html, i_taxi.html _ _ _ _ _ __ _ _ _ _ _ _ _ _ _ _ _ _ _
const button = document.querySelector("#btn");
button.addEventListener("click", calculateAmount);
const buttonTip = document.querySelector("#addTip");
buttonTip.addEventListener("click", showTip);
function showTip(e) {
e.preventDefault();
tip.style.display ="block";
}
let confett = document.querySelector("#my-canvas");
let btnClose = document.querySelector(".close");
function calculateAmount(e) {
e.preventDefault();
const bill = document.querySelector("#bill").value;
const people = document.querySelector("#people").value;
const tip = document.querySelector("#tip").value;
if(bill==="" || people==="" || people < 1) {
Swal.fire({
icon: 'error',
title: 'Error!',
text: 'Please enter your information!'
});
}
// how much for 1 person _ _ _
let amountPerPerson = bill/people;
// how much tips for 1 person _ _ _
let tipPerPerson = (bill*tip)/people;
// how much all money for 1 person _ _ _
let totalSum = amountPerPerson + tipPerPerson;
// toFixed() _ _ _
amountPerPerson = amountPerPerson.toFixed(2);
tipPerPerson = tipPerPerson.toFixed(2);
totalSum = totalSum.toFixed(2);
// show in app _ _ _
document.querySelector("#dividedBill").textContent = amountPerPerson;
document.querySelector("#dividedTip").textContent = tipPerPerson;
document.querySelector("#billAndTip").textContent = totalSum;
confett.classList.add('active');
btnClose.classList.add('active');
}
btnClose.addEventListener("click", ()=>{
document.location.reload();
});
const confettiSettings = { target: 'my-canvas' };
const confetti = new ConfettiGenerator(confettiSettings);
confetti.render();