Skip to main content

JavaScript Output — exercises and bug fixes

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

    Write plain text

    easy10 min

    Put the word "plain" into #out using textContent.

  2. 2

    Write markup safely

    easy10 min

    Show the literal text "<b>raw</b>" without it becoming bold.

  3. 3

    Render real markup

    easy10 min

    Use innerHTML so the word "bold" renders inside a <b> tag.

  4. 4

    Show a number

    easy10 min

    Show the result of 9 plus 6.

  5. 5

    Replace existing text

    medium10 min

    Overwrite whatever #out currently holds with "replaced".

Find the bug(5)

  1. 1

    Fix the appended text

    easy8 min

    Using += keeps the old placeholder and the stale label instead of replacing everything.

  2. 2

    Fix innerHTML used for plain text

    easy8 min

    The tags render instead of showing literally.

  3. 3

    Fix the missing space

    easy8 min

    The two words are joined with no space between them.

  4. 4

    Fix the value property

    easy8 min

    value only works on form fields, not a paragraph.

  5. 5

    Fix the missing conversion

    easy8 min

    The sum is joined as text because one side is a string.

Ready to write the code?

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

Open the workspace