Skip to main content

JavaScript Comments — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Comments 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 a line comment

    easy10 min

    Explain the line with a // comment, then show "documented".

  2. 2

    Use a block comment

    easy10 min

    Add a /* */ comment above the code, then show "blocked".

  3. 3

    Comment out a line

    easy10 min

    Disable the wrong line with a comment so "correct" is shown.

  4. 4

    Comment at the end of a line

    easy10 min

    Add a trailing comment after the statement.

  5. 5

    Keep code readable

    medium10 min

    Explain a calculation with a comment and show "clear".

Find the bug(5)

  1. 1

    Fix the unclosed block comment

    easy8 min

    The block comment never closes, so the real code is swallowed.

  2. 2

    Fix the commented-out code

    easy8 min

    The working line was accidentally commented out.

  3. 3

    Fix the wrong comment marker

    easy8 min

    A hash is not a JavaScript comment.

  4. 4

    Fix the comment that hides half a line

    easy8 min

    The comment starts too early and disables the assignment.

  5. 5

    Fix the nested block comment

    easy8 min

    Block comments cannot nest, so this breaks.

Ready to write the code?

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

Open the workspace