Skip to content

Commit 351c268

Browse files
committed
Change bill amount for product/price table
1 parent 5d698b5 commit 351c268

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

projects/tip-calculator/index.html

+22-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,28 @@
1111
<div class="container">
1212
<h1>Tip Calculator</h1>
1313
<p>Enter the bill amount and tip percentage to calculate the total.</p>
14-
<label for="bill">Bill amount:</label>
15-
<input type="number" id="bill">
14+
<table>
15+
<tr>
16+
<th>Product</th>
17+
<th>Price</th>
18+
</tr>
19+
<tr>
20+
<td>
21+
<input type="text" id="product-one">
22+
</td>
23+
<td>
24+
<input type="number" id="price-one">
25+
</td>
26+
</tr>
27+
<tr>
28+
<td>
29+
<input type="text" id="product-two">
30+
</td>
31+
<td>
32+
<input type="number" id="price-two">
33+
</td>
34+
</tr>
35+
</table>
1636
<br/>
1737
<label for="tip">Tip percentage:</label>
1838
<input type="number" id="tip">

projects/tip-calculator/index.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
11
const btnCalculate = document.getElementById("calculate");
22
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");
47
const tipInput = document.getElementById("tip");
58
const subtotalSpan = document.getElementById("subtotal");
69
const finalTipSpan = document.getElementById("final-tip");
710
const totalSpan = document.getElementById("total");
811

912
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);
1116
const tipValue = tipInput.value;
17+
subtotalSpan.innerText = billValue;
1218
if(tipValue<20){
1319
const finalTipValue = billValue * tipValue / 100;
1420
const totalValue = billValue * (1 + tipValue / 100);
15-
subtotalSpan.innerText = billValue;
1621
finalTipSpan.innerText = finalTipValue.toFixed(2);
1722
totalSpan.innerText = totalValue.toFixed(2);
1823
}
1924
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";
2527
}
26-
27-
2828
}
2929

3030
function cleanTotal() {
31-
billInput.value=null;
31+
productOneInput.value=null;
32+
productTwoInput.value=null;
33+
priceOneInput.value=null;
34+
priceTwoInput.value=null;
3235
tipInput.value=null;
3336
subtotalSpan.innerText = "";
3437
finalTipSpan.innerText = "";

projects/tip-calculator/style.css

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
box-sizing: border-box;
33
}
44

5+
table {
6+
font-family: arial, sans-serif;
7+
border-collapse: collapse;
8+
width: 100%;
9+
}
10+
11+
td,
12+
th {
13+
border: 1px solid #dddddd;
14+
text-align: left;
15+
padding: 15px;
16+
}
17+
518
body {
619
background-color: #f2f2f2;
720
font-family: "Helvetica", sans-serif;

0 commit comments

Comments
 (0)