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.
Try it yourself
Compare exact boundary ratios and invalid session inputs.
| Case | Result |
|---|---|
| attended = 8, totalSessions = 10 (80%) | Select a choice above to see what happens. |
| attended = 6, totalSessions = 10 (60%) | Select a choice above to see what happens. |
| attended = 0, totalSessions = 0 | Select a choice above to see what happens. |
Reveal the explanation
- attended = 8, totalSessions = 10 (80%)
"ELIGIBLE". Exact 80% cutoff qualifies.
- attended = 6, totalSessions = 10 (60%)
"WARNING". Between 60% inclusive and 80% exclusive.
- 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.
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
This browser could not save your progress. Changes last until you leave the page.