Skip to main content

JavaScript DOM Content — exercises and bug fixes

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

    Set plain text

    easy10 min

    Set the box text to Hello and report what it says.

  2. 2

    Insert real markup

    easy10 min

    Put a strong element inside the box, then report how many exist.

  3. 3

    Read text without the tags

    easy10 min

    Report the box text with its tags stripped out.

  4. 4

    Treat markup as text

    easy10 min

    Put the tag text in as plain text and report how many strong elements exist.

  5. 5

    Build a list from an array

    medium10 min

    Build the list items in one string and report how many were made.

Find the bug(5)

  1. 1

    Fix innerHTML used for untrusted text

    easy8 min

    Text from a visitor must not be treated as markup.

  2. 2

    Fix textContent used for markup

    easy8 min

    The strong element needs creating, so the tags must be parsed.

  3. 3

    Fix the content that was replaced

    easy8 min

    Assigning wipes what was there; the new item should be added.

  4. 4

    Fix innerHTML used to read plain text

    easy8 min

    The tags should not appear in the answer.

  5. 5

    Fix the value never converted

    easy8 min

    The array is being assigned directly instead of being joined into markup.

Ready to write the code?

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

Open the workspace