Skip to content

Commit ed1f527

Browse files
committed
Add comments
1 parent a38d52d commit ed1f527

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ <h1>Tip Calculator</h1>
1515
step="0.01"
1616
required
1717
/><br />
18-
<button id="calculate">Calculate Tip Amount</button>
18+
<!--button to calculate total amount--><button id="calculate">
19+
Calculate Tip Amount
20+
</button>
1921
<div id="output"></div>
2022
<script src="main.js"></script>
2123
</body>

main.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
const amountInput = document.getElementById("amount");
2-
const tipPercentInput = document.getElementById("tip-percent");
3-
const calculateButton = document.getElementById("calculate");
4-
const outputText = document.getElementById("output");
1+
const amountInput = document.getElementById("amount"); //amount input
2+
const tipPercentInput = document.getElementById("tip-percent"); //tip percent input
3+
const calculateButton = document.getElementById("calculate"); //calculate button
4+
const outputText = document.getElementById("output"); //output text
55
calculateButton.addEventListener("click", () => {
6-
let amount = parseFloat(amountInput.value);
7-
let tipPercent = parseFloat(tipPercentInput.value);
8-
let totalAmount = amount * (1 + tipPercent / 100);
9-
outputText.innerText = `Total Amount: ${totalAmount.toFixed(2)}`;
6+
//when calculate button is pressed
7+
let amount = parseFloat(amountInput.value); //get amount value
8+
let tipPercent = parseFloat(tipPercentInput.value); //get tip percent value
9+
let totalAmount = amount * (1 + tipPercent / 100); //get total billing amount
10+
outputText.innerText = `Total Amount: ${totalAmount.toFixed(2)}`; //format total billing amount
1011
});

0 commit comments

Comments
 (0)