Master JavaScript loops through 12 desi, story-based challenges! From Raju ki chai tapri to IRCTC tatkal booking, each problem puts you in a real Indian scenario where you need to write the logic using for, while, do...while, for...of, and nested loops.
Total: 100 points across 12 challenges
Click the GitHub Classroom invitation link shared by your instructor. This will create a personal copy of this repository under your GitHub account.
git clone <your-repo-url>
cd js-loops-labReplace <your-repo-url> with the URL from your GitHub Classroom repo (the green Code button).
npm installnpm testYou should see all tests failing — that's expected! Your job is to make them pass.
All challenges live in the src/ folder. Start with src/01-chai-tapri.js and work your way up.
src/
├── 01-chai-tapri.js ← Start here
├── 02-cricket-scoreboard.js
├── 03-auto-rickshaw-meter.js
├── 04-bollywood-playlist.js
├── 05-sabzi-mandi.js
├── 06-diwali-lights.js
├── 07-ipl-points-table.js
├── 08-emi-calculator.js
├── 09-upi-retry.js
├── 10-biryani-order.js
├── 11-rangoli-pattern.js
└── 12-indian-railways.js
Each file has a detailed JSDoc comment at the top that explains:
- The kahani (story — a real Indian scenario)
- The rules your function must follow
- The parameters and return values
Read it carefully — every edge case and requirement is described there.
Replace // Your code here with your implementation:
// Before
export function chaiTapriRevenue(customers) {
// Your code here
}
// After (example)
export function chaiTapriRevenue(customers) {
if (!Number.isInteger(customers) || customers <= 0) {
return { totalChai: 0, totalRevenue: 0 };
}
let totalRevenue = 0;
for (let i = 1; i <= customers; i++) {
// ... your logic
}
return { totalChai: customers, totalRevenue };
}npm test -- 01-chaiYou can use any part of the filename to match:
npm test -- 02-cricket
npm test -- 03-auto
npm test -- bollywood
npm test -- sabzi
npm test -- biryaniIf tests fail, read the error messages — they tell you exactly what was expected vs. what your function returned. Fix your code and run the test again.
Once all tests pass for a challenge, move on to the next one. They get progressively harder.
npm testnpm run test:watchThis re-runs tests every time you save a file — very handy while working.
| # | File | Kahani | Loop Concept | Points |
|---|---|---|---|---|
| 01 | 01-chai-tapri.js |
Raju ki Chai Tapri | Basic for loop, modulo, accumulator |
7 |
| 02 | 02-cricket-scoreboard.js |
Gully Cricket Scoreboard | for loop, break, multiple counters |
7 |
| 03 | 03-auto-rickshaw-meter.js |
Pappu ka Auto Meter | while loop, rate tiers, Math.ceil |
8 |
| 04 | 04-bollywood-playlist.js |
Simran ki Road Trip Playlist | while with lookahead, skip invalid |
8 |
| 05 | 05-sabzi-mandi.js |
Amma ki Sabzi Mandi | for...of, object lookup, array building |
8 |
| 06 | 06-diwali-lights.js |
Sharma ji ki Diwali Lights | for...of + while trim, budget constraint |
8 |
| 07 | 07-ipl-points-table.js |
IPL Season Points Table | for with object accumulator, sorting |
9 |
| 08 | 08-emi-calculator.js |
Rohit ka Phone EMI | while accumulator, infinite loop guard |
9 |
| 09 | 09-upi-retry.js |
Bunty ka UPI Retry | do...while, exponential backoff |
8 |
| 10 | 10-biryani-order.js |
Paradise Biryani Batches | do...while with state, queue processing |
8 |
| 11 | 11-rangoli-pattern.js |
Priya ki Diwali Rangoli | Nested for loops, diamond pattern |
10 |
| 12 | 12-indian-railways.js |
IRCTC Tatkal Reservation | Nested loops, multi-pass, mutation | 10 |
Run all tests to see how many you've solved:
npm testgit add src/Important: Only add files from
src/. Do not modify or commit test files.
git commit -m "Complete loops lab"You can commit as many times as you want — each push triggers a new grading run.
git push origin mainAfter pushing, go to your repository on GitHub:
- Click the Actions tab
- You'll see a workflow run in progress (or completed)
- Click on it to see which tests passed and your total score out of 100
You can push again to improve your score — GitHub Classroom will always use the latest result.
- JSDoc dhyan se padho — every rule and edge case is described there
- Boundary values check karo — tests often check exact boundaries
- Loop type matters — some problems specifically need
for,while,do...while, orfor...of - Return types matter — most functions return objects, check the exact shape
- Don't modify the test files — only edit files in
src/ - Commit often — don't wait until you've solved everything to push
- Use
console.log()— add temporary logs to debug, then remove them before submitting
forloops with counters and accumulatorswhileloops with dynamic conditionsdo...whileloops (execute at least once)for...ofloops for iterating arraysbreakstatement to exit loops early- Nested loops for complex patterns
- Object accumulators (building objects in loops)
- Array building within loops
Math.ceil()for rounding up- Exponential backoff pattern
- Input validation and edge cases
| Problem | Solution |
|---|---|
npm test shows "command not found" |
Run npm install first |
All tests fail with undefined |
You haven't written your solution yet — that's expected |
| Tests say "expected X but received Y" | Your logic is close but not matching the rules — re-read the JSDoc |
git push is rejected |
Run git pull origin main first, then push again |
| Tests pass locally but fail on GitHub | Make sure you pushed all your changes (git status to check) |
Good luck! Aur haan, chai peete peete code karna!