JavaScript else if Statement — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript else if Statement lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Grade a score
easy10 minShow "A" for 90+, "B" for 80+, otherwise "C". The score is 85.
- 2
Describe a temperature
easy10 minShow "hot" above 30, "warm" above 20, otherwise "cold". It is 25.
- 3
Map a role to access
easy10 minadmin sees "full", editor sees "partial", anyone else "none". The role is editor.
- 4
Classify a number
easy10 minShow "negative", "zero" or "positive" for the value 0.
- 5
Pick a shipping band
medium10 minFree over 100, "standard" over 50, else "express". The total is 60.
Find the bug(5)
- 1
Fix the branch order
easy8 minThe widest test comes first, so it swallows every score.
- 2
Fix the separate ifs
easy8 minTwo independent ifs both run, so the last one wins.
- 3
Fix the missing else
easy8 minAn unmatched value leaves the output untouched.
- 4
Fix the zero test
easy8 minZero falls into the negative branch because the comparison includes it.
- 5
Fix the unreachable branch
easy8 minThe final band can never be reached as written.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace