Lab · JavaScript Programming (language in depth)
Lab: which recharge plan is cheaper?
The brief
Your family has three prepaid SIMs and everyone argues about plans: ₹299 for 28 days or ₹719 for 84? Write small functions with numbers and Math to find the cost per day, split out the 18% GST, compare two plans and print prices as rupees.
Why it matters
Comparison sites, telecom apps and every "plans" page do this maths, and money maths is where beginners meet JavaScript's number traps: decimals that do not add up exactly, rounding, and dividing the right way round. Getting it right early saves real bugs later.
Skills you practise
- numbers and arithmetic operators
- operator precedence
- Math.round and rounding to 2 decimals
- comparison operators and booleans
- toFixed and string joining
- functions that return values
What you will have at the end
recharge.js: four tested functions that compare prepaid plans fairly and show the answer in rupees.
How it is marked (rubric, 100 points)
| Correct numbersEvery check passes. | 50 |
|---|---|
| Right mathsGST removed by dividing by 1.18; rounding done once, at the end. | 25 |
| Clear codeShort functions with good names; one function reuses another. | 15 |
| Can explainYou can explain why 299 × 0.82 is the wrong way to remove GST. | 10 |
0/4 steps done
Step 1 of 4
Cost per day
perDay(price, days) returns the price per day, rounded to 2 decimal places (₹299 for 28 days is 10.68).
Divide the price by the number of days. 299 / 28 is 10.678571…, but money has paise, so round to 2 decimal places. Math.round only rounds to a whole number, so multiply by 100 first, round, then divide by 100: 1067.857… becomes 1068, then 10.68.
Run shows what your code prints. Check runs the step's tests. Ctrl+Enter checks too.