|
1 | 1 | const btnCalculate = document.getElementById("calculate");
|
2 | 2 | const btnClean = document.getElementById("clean");
|
3 |
| -const billInput = document.getElementById("bill"); |
| 3 | +const productOneInput = document.getElementById("product-one"); |
| 4 | +const productTwoInput = document.getElementById("product-two"); |
| 5 | +const priceOneInput = document.getElementById("price-one"); |
| 6 | +const priceTwoInput = document.getElementById("price-two"); |
4 | 7 | const tipInput = document.getElementById("tip");
|
5 | 8 | const subtotalSpan = document.getElementById("subtotal");
|
6 | 9 | const finalTipSpan = document.getElementById("final-tip");
|
7 | 10 | const totalSpan = document.getElementById("total");
|
8 | 11 |
|
9 | 12 | function calculateTotal() {
|
10 |
| - const billValue = billInput.value; |
| 13 | + const priceOneValue = 0 + priceOneInput.value; |
| 14 | + const priceTwoValue = 0 + priceTwoInput.value; |
| 15 | + const billValue = parseFloat(priceOneValue) + parseFloat(priceTwoValue); |
11 | 16 | const tipValue = tipInput.value;
|
| 17 | + subtotalSpan.innerText = billValue; |
12 | 18 | if(tipValue<20){
|
13 | 19 | const finalTipValue = billValue * tipValue / 100;
|
14 | 20 | const totalValue = billValue * (1 + tipValue / 100);
|
15 |
| - subtotalSpan.innerText = billValue; |
16 | 21 | finalTipSpan.innerText = finalTipValue.toFixed(2);
|
17 | 22 | totalSpan.innerText = totalValue.toFixed(2);
|
18 | 23 | }
|
19 | 24 | else{
|
20 |
| - subtotalSpan.innerText = billValue; |
21 |
| - finalTipValue = "The tip is abusive"; |
22 |
| - finalTipSpan.innerText = finalTipValue; |
23 |
| - totalValue = "The tip is abusive"; |
24 |
| - totalSpan.innerText = totalValue; |
| 25 | + finalTipSpan.innerText = "The tip is abusive"; |
| 26 | + totalSpan.innerText = "The tip is abusive"; |
25 | 27 | }
|
26 |
| - |
27 |
| - |
28 | 28 | }
|
29 | 29 |
|
30 | 30 | function cleanTotal() {
|
31 |
| -billInput.value=null; |
| 31 | +productOneInput.value=null; |
| 32 | +productTwoInput.value=null; |
| 33 | +priceOneInput.value=null; |
| 34 | +priceTwoInput.value=null; |
32 | 35 | tipInput.value=null;
|
33 | 36 | subtotalSpan.innerText = "";
|
34 | 37 | finalTipSpan.innerText = "";
|
|
0 commit comments