Skip to main content

JavaScript Ternary Operator — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Ternary Operator 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

    Choose between two values

    easy10 min

    Report adult when the age is 18 or more.

  2. 2

    Pick the singular or plural

    easy10 min

    Report the right wording for a count of one.

  3. 3

    Return from a function

    easy10 min

    Return a lower fee for members.

  4. 4

    Chain two ternaries

    easy10 min

    Report a grade of B for a score of 75.

  5. 5

    Use it inside a string

    medium10 min

    Build a sentence that changes with the value.

Find the bug(5)

  1. 1

    Fix the branches the wrong way round

    easy8 min

    The true and false values have been swapped.

  2. 2

    Fix the singular and plural swapped

    easy8 min

    A count of two should read items, not item.

  3. 3

    Fix the missing brackets

    easy8 min

    Without brackets the join happens before the choice.

  4. 4

    Fix the comparison that is always true

    easy8 min

    A single equals assigns instead of comparing.

  5. 5

    Fix the grade boundaries

    easy8 min

    A score of 75 should be a B, not a C.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace