-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
28 lines (24 loc) · 959 Bytes
/
main.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
function calculate() {
let billAmount = document.getElementById('billAmount').value;
let numberOfPeople = document.getElementById('numberOfPeople').value;
let opinion = document.getElementById('opinion');
let opinionValue = opinion.options[opinion.selectedIndex].value;
let percentOfTip;
if (opinionValue === 'best') {
percentOfTip = 0.30;
} else if (opinionValue === 'good') {
percentOfTip = 0.20;
} else if (opinionValue === 'poor') {
percentOfTip = 0.10;
}
let result = document.getElementById('result');
if (billAmount.length > 0 && numberOfPeople.length > 0) {
if (opinionValue === '') {
result.innerHTML = 'Select your opinion!';
} else {
result.innerHTML = 'Result: ' + Math.round((billAmount * percentOfTip) / numberOfPeople) + '$';
}
} else {
result.innerHTML = 'Inputs are blank!';
}
}