Skip to main content

JavaScript Statements — exercises and bug fixes

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

    Run statements in order

    easy10 min

    Set a value, change it, then show the final one.

  2. 2

    Write a declaration statement

    easy10 min

    Declare a constant and display it.

  3. 3

    Use a conditional statement

    easy10 min

    Show "branching" when a flag is true.

  4. 4

    Use a loop statement

    easy10 min

    Loop three times and report "looped".

  5. 5

    Combine several statements

    medium10 min

    Declare, calculate and display in three statements.

Find the bug(5)

  1. 1

    Fix the statements in the wrong order

    easy8 min

    The value is displayed before it is updated.

  2. 2

    Fix the statement inside the wrong block

    easy8 min

    The display line only runs when the flag is false.

  3. 3

    Fix the incomplete statement

    easy8 min

    The assignment has no value on the right.

  4. 4

    Fix the loop count

    easy8 min

    The loop runs the wrong number of times.

  5. 5

    Fix the wrong operator in the calculation

    easy8 min

    Adding instead of multiplying gives the wrong total.

Ready to write the code?

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

Open the workspace