Skip to main content

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

    Grade a score

    easy10 min

    Show "A" for 90+, "B" for 80+, otherwise "C". The score is 85.

  2. 2

    Describe a temperature

    easy10 min

    Show "hot" above 30, "warm" above 20, otherwise "cold". It is 25.

  3. 3

    Map a role to access

    easy10 min

    admin sees "full", editor sees "partial", anyone else "none". The role is editor.

  4. 4

    Classify a number

    easy10 min

    Show "negative", "zero" or "positive" for the value 0.

  5. 5

    Pick a shipping band

    medium10 min

    Free over 100, "standard" over 50, else "express". The total is 60.

Find the bug(5)

  1. 1

    Fix the branch order

    easy8 min

    The widest test comes first, so it swallows every score.

  2. 2

    Fix the separate ifs

    easy8 min

    Two independent ifs both run, so the last one wins.

  3. 3

    Fix the missing else

    easy8 min

    An unmatched value leaves the output untouched.

  4. 4

    Fix the zero test

    easy8 min

    Zero falls into the negative branch because the comparison includes it.

  5. 5

    Fix the unreachable branch

    easy8 min

    The 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