Skip to content

Lab · Frontend Web Development

Lab: split the hostel dinner bill

Labbeginner· about 1.5 hours· 5 steps

The brief

Five hostel friends eat at a South Indian restaurant in Chennai and want to split the bill fairly. Write small JavaScript functions: add up the items, add GST, apply a coupon, split the total into whole-rupee shares that add up exactly, and print a price list.

Why it matters

Every food-delivery and bill-splitting app does this maths, and getting it wrong by one rupee causes real complaints. These are also the exact kinds of small functions you write in front-end interviews: loops, conditions, rounding and array methods.

Skills you practise

  • let and const
  • for…of loops
  • if / else and comparisons
  • Math.round, Math.floor and %
  • functions that return values
  • arrays and map

What you will have at the end

bill.js: five tested functions that turn a list of dishes into a fair, GST-correct split for a group.

How it is marked (rubric, 100 points)
Correct resultsEvery check passes, including the empty order and the 0-people case.50
Clear codeGood names, const where a value does not change, no copied code.25
Money handled safelyWhole rupees, rounding in one place, shares that add up exactly.15
Can explain itYou can explain why 1000 / 3 needs the leftover rupees handed out.10

0/5 steps done

Step 1 of 5

Add up the items

billTotal(prices) returns the sum of the prices; an empty array gives 0.

Start a running total at 0 with let (it changes), then add each price with a for…of loop. Return the total instead of printing it, so other functions can use the answer. An empty order should cost 0, and a loop that never runs gives exactly that.

Run shows what your code prints. Check runs the step's tests. Ctrl+Enter checks too.