JavaScript · Exercise 6 of 6 Previous
Intermediate
Build a bill splitter
Build a small app that splits a restaurant bill, with a pure core and an impure shell.
Pure core: calcSplit(bill, tipPercent, people) returns how much each person pays, including the tip, rounded to 2 decimals (as a number). If people is less than 1, it returns null. It must not touch the page.
Impure shell: when Split is clicked, read the three inputs, call calcSplit, and show the result in #result as ₹275.00 per person (two decimals). If calcSplit returns null, show Enter at least 1 person instead.
What Check tests
calcSplit(1000, 10, 4)is 275- The result is rounded to 2 decimals:
calcSplit(100, 15, 3)is 38.33 calcSplitreturnsnullfor fewer than 1 personcalcSplitis pure: same answer twice, page untouched- Clicking Split shows
₹275.00 per person - With 0 people the page asks for at least 1 person
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Your page
Press Run to see the page.
Console
Nothing logged yet.