Command Palette

Search for a command to run...

Hectal
Phase 4: Strings, Numbers and Dates
JavaScript · Exercise 4 of 5 PreviousNext
Beginner

Split the bill to the paisa

Three friends share a ₹1000 dinner. Split it so the shares are whole paise, differ by at most one paisa, and add up exactly to the total.

Write three functions: toPaise(rupees) turns a rupee amount into whole paise; splitBill(totalRupees, people) returns an array of shares in paise; formatINR(paise) returns the amount formatted for India, like ₹12,34,567.89.

The page code already lists each share in #shares.

What Check tests

  1. toPaise(4.35) is exactly 435
  2. ₹100 for 3 adds up to 10000 paise, with shares at most 1 apart
  3. ₹0.30 for 3 is 10 paise each
  4. formatINR(123456789) gives ₹12,34,567.89
  5. The page lists ₹333.34, ₹333.33 and ₹333.33

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.