Skip to content

Repository files navigation

Fare Splitter

Build a small calculator that divides a bill without silently accepting broken input.

Pair this exercise with the JavaScript notes.

Start your own copy

  1. On GitHub, click Use this templateCreate a new repository.
  2. Choose whether your repository will be public or private.
  3. 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

Run it

From this repository's root:

python3 -m http.server 8000

Open http://127.0.0.1:8000/.

Build steps

  1. Finish calculateShare in script.js as a pure function.
  2. Read both form values on submit and convert them to numbers.
  3. Reject a total below zero and a people count below one.
  4. Round up to the nearest cent so the split never comes up short.
  5. Put the result or a useful error in the live status region.

Acceptance checklist

  • 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.

Test cases

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.

Get your automatic project grade

  1. Create your own copy from this template.

  2. Read MASTERY.md, then create an attempt branch:

    git switch -c attempt/my-project
  3. Build the project and run the same check GitHub uses:

    node --test test/mastery.test.mjs
  4. 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.

About

Beginner JavaScript lab for splitting a fare with functions, validation, rounding, and accessible status messages.

Topics

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages