Build a small calculator that divides a bill without silently accepting broken input.
Pair this exercise with the JavaScript notes.
- On GitHub, click Use this template → Create a new repository.
- Choose whether your repository will be public or private.
- Clone your new repository, then make changes in your own copy.
Lesson milestone: Session 2 — functions, return values, number conversion, and validation
Time-box: 45–60 minutes
Dependencies: none
From this repository's root:
python3 -m http.server 8000Open http://127.0.0.1:8000/.
- Finish calculateShare in script.js as a pure function.
- Read both form values on submit and convert them to numbers.
- Reject a total below zero and a people count below one.
- Round up to the nearest cent so the split never comes up short.
- Put the result or a useful error in the live status region.
- Pressing Enter submits the form.
- KSh 1,000 split by 3 shows KSh 333.34 per person.
- Zero people, a negative total, and an empty field each show a helpful error.
- The calculation lives in a function with inputs and a return value.
- Repeated submissions replace the old result.
- There are no console errors.
| Total | People | Expected |
|---|---|---|
| 1000 | 3 | KSh 333.34 |
| 0 | 2 | KSh 0.00 |
| -10 | 2 | Error |
| 500 | 0 | Error |
Work through the validation branch yourself and explain each decision aloud as you test it.
-
Create your own copy from this template.
-
Read MASTERY.md, then create an attempt branch:
git switch -c attempt/my-project
-
Build the project and run the same check GitHub uses:
node --test test/mastery.test.mjs
-
Commit and push the attempt branch:
git add . git commit -m "Complete project attempt" git push -u origin attempt/my-project
GitHub Actions grades every pushed attempt automatically. PASS — NAILED IT means every required check passed. REVISE — KEEP BUILDING means the run shows what to fix before you push again. You do not need the KODE Ń VIBE owner to review or start anything; the template's main branch stays quiet on purpose.
The free grading guide explains the result and its limits.