Split a Bill with a Tip
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Build a tip calculator. A text input labelled "Bill" starts empty. Three radio buttons named "10%", "15%" and "20%" pick the tip, with 15% chosen at first. A text input labelled "People" starts at 1. Show three lines, "Tip: ", "Total: " and "Each: ", each followed by the amount to two decimal places: a bill of 80 at 15% for 2 people shows "Tip: 12.00", "Total: 92.00" and "Each: 46.00" (each person pays the total divided by People). While the bill is empty, not a number or not above 0, show "Enter the bill amount" instead of the three lines. If the bill is fine but People isn't a whole number of at least 1, show "Enter how many people" instead.
Your code must pass
- Asks for the bill until one is entered
- Works out the tip, total and each share
- Picking another tip recalculates
- A bad bill or head count asks again