1 let explanation = document.getElementById("explanation"); 2 let input = document.getElementById("input"); 3 let button = document.getElementById("button"); 4 let output = document.getElementById("output"); 5 let select = document.getElementById("service"); 6 7 explanation.innerHTML = "Enter the cost of your meal. "; 8 explanation.innerHTML += "Then press Calculate. "; 9 button.onclick = calculateTip; 10
11 function calculateTip() 12 { 13 let cost = parseFloat(input.value); 14 let percent = parseFloat(select.value); 15 let tip = cost * percent / 100; 16 tip = tip.toFixed(2); 17 let text = "A " + percent + "% tip is $" + tip; 18 output.innerHTML = text; 19 let total = cost + parseFloat(tip); 20 output.innerHTML += "<br>The total cost is $" + total; 21 } 22