Skip to main content

JavaScript Semicolons — exercises and bug fixes

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

    End statements with semicolons

    easy10 min

    Write two terminated statements and show the second value.

  2. 2

    Separate statements on one line

    easy10 min

    Two statements on one line need a semicolon between them.

  3. 3

    Terminate a declaration

    easy10 min

    Declare a value, end the statement, then display it.

  4. 4

    Return on the same line

    easy10 min

    Return a value on the same line as return to avoid ASI problems.

  5. 5

    Terminate before a parenthesis

    medium10 min

    A missing semicolon before a ( can join two lines — avoid it here.

Find the bug(5)

  1. 1

    Fix the return broken by a newline

    easy8 min

    A newline after return makes it return undefined.

  2. 2

    Fix the missing separator

    easy8 min

    Two statements share a line with no semicolon between them.

  3. 3

    Fix the comma used as a terminator

    easy8 min

    A comma continues the declaration instead of ending it.

  4. 4

    Fix the semicolon after if

    easy8 min

    A semicolon straight after if() ends the statement early.

  5. 5

    Fix the missing semicolon before a bracket

    easy8 min

    The next line is treated as an index of the previous value.

Ready to write the code?

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

Open the workspace