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
Set plain text
easy10 minSet the box text to Hello and report what it says.
- 2
Insert real markup
easy10 minPut a strong element inside the box, then report how many exist.
- 3
Read text without the tags
easy10 minReport the box text with its tags stripped out.
- 4
Treat markup as text
easy10 minPut the tag text in as plain text and report how many strong elements exist.
- 5
Build a list from an array
medium10 minBuild the list items in one string and report how many were made.
Find the bug(5)
- 1
Fix innerHTML used for untrusted text
easy8 minText from a visitor must not be treated as markup.
- 2
Fix textContent used for markup
easy8 minThe strong element needs creating, so the tags must be parsed.
- 3
Fix the content that was replaced
easy8 minAssigning wipes what was there; the new item should be added.
- 4
Fix innerHTML used to read plain text
easy8 minThe tags should not appear in the answer.
- 5
Fix the value never converted
easy8 minThe 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