Tip Calculator and Bill Splitter
Easy
Build a tip calculator and bill splitter component that allows users to enter a bill total, tip percentage, and number of guests to compute individual and grand totals in real time.
Requirements
- Bill Amount Input: Include an input labeled
Bill Amount ($)(typenumber, minimum0). - Tip Percentage Input: Include an input labeled
Tip Percentage (%)(typenumber, minimum0) with a default value of15. - Number of People Input: Include an input labeled
Number of People(typenumber, minimum1) with a default value of1. - Calculated Results: Display three computed values formatted as currency (
$0.00standard formatting with 2 decimal places):- Tip per Person: Identified by label/text
Tip per Person. - Total per Person: Identified by label/text
Total per Person. - Grand Total: Identified by label/text
Grand Total.
- Tip per Person: Identified by label/text
- Calculation Logic:
- Tip per Person =
(Bill * (Tip % / 100)) / Number of People. - Total per Person =
(Bill + Total Tip) / Number of People. - Grand Total =
Bill + Total Tip. - If the bill amount is empty, 0, or negative, or if the number of people is less than 1, display
$0.00for all calculated amounts.
- Tip per Person =
- Reset Action: Include a button labeled
Resetthat resets the form fields back to their defaults (Bill Amount ($)to empty string or0,Tip Percentage (%)to15,Number of Peopleto1).
The setup
ReactTypeScriptTailwind CSSBuild from specEnd-to-end
The files open on a skeleton. Build the behaviour the requirements describe.
- src/main.tsx
- src/App.tsx
- src/styles.css
Follow-up: How would you extend this component to support split presets (like splitting evenly vs custom itemized splits)?
Constraints:
Use semantic form elements with clear accessible labels for all inputs.
- Accepted
- 2/2
- Acceptance Rate
- 100.0%
- Views
- 1