Skip to main content

JavaScript Expressions — exercises and bug fixes

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

    Evaluate an arithmetic expression

    easy10 min

    Show whether 3 * 7 equals 21.

  2. 2

    Evaluate a string expression

    easy10 min

    Join "code" and "base" and confirm the result.

  3. 3

    Use a comparison expression

    easy10 min

    Show whether 8 is greater than 3.

  4. 4

    Use a ternary expression

    easy10 min

    Show "even" or "odd" for the number 10.

  5. 5

    Combine expressions

    medium10 min

    Confirm that (2 + 3) * 2 equals ten.

Find the bug(5)

  1. 1

    Fix the precedence in the expression

    easy8 min

    Missing parentheses change the result.

  2. 2

    Fix the assignment used as an expression

    easy8 min

    A single = assigns rather than compares.

  3. 3

    Fix the reversed ternary

    easy8 min

    The two outcomes are swapped.

  4. 4

    Fix the comparison direction

    easy8 min

    The comparison points the wrong way.

  5. 5

    Fix the numeric string join

    easy8 min

    The values are joined as text instead of added.

Ready to write the code?

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

Open the workspace