-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (31 loc) · 1.17 KB
/
index.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
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';
}
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: 'Oops...',
text: 'Something went wrong!',
footer: '<a href="">Why do I have this issue?</a>'
})
}
let amountPerPerson = bill/people;
let tipPerPerson = (bill * tip) / people;
let totalSum = amountPerPerson + tipPerPerson;
amountPerPerson = amountPerPerson.toFixed(2);
tipPerPerson = tipPerPerson.toFixed(2);
totalSum =totalSum.toFixed(2)
document.querySelector('#dividedBill').textContent = amountPerPerson;
document.querySelector('#devidedTip').textContent = tipPerPerson;
document.querySelector('#billAndTip').textContent= totalSum;
}