Skip to main content

JavaScript Operators — exercises and bug fixes

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

    Add two numbers

    easy10 min

    Show the sum of 12 and 8.

  2. 2

    Find a remainder

    easy10 min

    Show the remainder of 17 divided by 5.

  3. 3

    Use exponentiation

    easy10 min

    Show 2 raised to the power of 5.

  4. 4

    Compare two values strictly

    easy10 min

    Show whether 10 is strictly equal to the string "10".

  5. 5

    Respect operator precedence

    medium10 min

    Show the result of 2 plus 3, multiplied by 4.

Find the bug(5)

  1. 1

    Fix the precedence mistake

    easy8 min

    The parentheses are missing, so the result is wrong.

  2. 2

    Fix the assignment used as a comparison

    easy8 min

    A single = overwrites x instead of comparing it, so this wrongly reports true.

  3. 3

    Fix the division that should be a remainder

    easy8 min

    This should report the remainder, not the quotient.

  4. 4

    Fix the increment placement

    easy8 min

    Post-increment shows the old value instead of the new one.

  5. 5

    Fix the inverted comparison

    easy8 min

    The comparison operator points the wrong way.

Ready to write the code?

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

Open the workspace