HTML CSS JS Projects
Project 3HTML · CSS · JS~45 min
Tip Calculator
User input, switch logic, and formatted currency
Track progress0/3 days
What you'll learn
getElementByIdparseFloatswitchtextContentevent listeners
- Read bill amount, service rating, split count, and meal type
- Calculate tip % with a switch statement
- Split the total between people
- Apply a dinner bonus and display formatted dollars
Lesson & examples
Read the code, then the explanation — try changing values before the project.
Read inputs
const billAmount = parseFloat(document.getElementById("billAmount").value);
const serviceRating = parseFloat(document.getElementById("serviceRating").value);Switch on rating
switch (serviceRating) {
case 1: tip = billAmount * 0.05; break;
case 2: tip = billAmount * 0.10; break;
case 3: tip = billAmount * 0.15; break;
case 4: tip = billAmount * 0.20; break;
}Display with toFixed
tipAmountOutput.textContent = `Tip: $${tip.toFixed(2)}`;