Curriculum

Curriculum

Build a Course Attendance Eligibility Checker

Scenario

Contract `checkAttendance(attended, totalSessions)`: invalid if either is non-integer, `totalSessions <= 0`, `attended < 0`, or `attended > totalSessions` → `INVALID_ATTENDANCE`. Use integer cross-multiplication (`attended * 100 >= 80 * totalSessions`) to avoid floating-point rounding traps.

Selected choicePick a choice below
Result—

Try it yourself

Compare exact boundary ratios and invalid session inputs.

Reveal the explanation
  1. attended = 8, totalSessions = 10 (80%)

    "ELIGIBLE". Exact 80% cutoff qualifies.

  2. attended = 6, totalSessions = 10 (60%)

    "WARNING". Between 60% inclusive and 80% exclusive.

  3. attended = 0, totalSessions = 0

    Error: INVALID_ATTENDANCE. Prevents division-by-zero traps.

Checking `totalSessions <= 0` and `attended > totalSessions` first prevents impossible percentages like `NaN` or `120%`. Checking the highest tier (`>= 80%`) before `>= 60%` keeps branches clean.

Review first
Download shared test cases

Your turn

Implement `checkAttendance` and pass every case in `fixture-attendance-eligibility`, including `3/5` (60%), `4/5` (80%), `0/0`, and `11/10`.

Common mistake Checking `>= 60%` before `>= 80%`, which traps 90% students in `"WARNING"`, or forgetting `totalSessions === 0`.

Check your work

Function using integer boundary comparison + passing test output for all 3 tiers and invalid cases.

Project brief

Basic
Implement the 3 ordered attendance tiers (`ELIGIBLE`, `WARNING`, `INELIGIBLE`) with exact 80% and 60% tests.
Intermediate
Guard `totalSessions <= 0`, `attended < 0`, `attended > totalSessions`, and non-integers with `INVALID_ATTENDANCE`.
Stretch
Accept a boolean array `[true, false, true]` of session records and compute `attended` and `totalSessions` first.

What to hand in

Include your diagram, expected-result table, code, actual test output, and the commit or diff you reviewed.

Review criteria

  • Logic · Your diagram shows every required path and boundary.
  • Verification · The tests exercise the stated acceptance cases and the recorded results match the code.
  • Review · The change is focused and you can explain the decision it implements.

Quick check

Why is `attended * 100 >= 80 * totalSessions` safer than floating-point division in cross-language contracts?
Show the answer and reasoning

Correct answer Exact integer math avoids rounding differences across Python, JavaScript, and Go

Integer cross-multiplication is exact across languages and avoids `0.7999999999999999` floating-point surprises.