File tree Expand file tree Collapse file tree 2 files changed +12
-9
lines changed
Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Original file line number Diff line number Diff 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 >
Original file line number Diff line number Diff line change 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
55calculateButton . 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} ) ;
You can’t perform that action at this time.
0 commit comments