JavaScript DOM Traversal — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript DOM Traversal 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
Find the parent
easy10 minReport the id of the paragraph's parent.
- 2
Read the first child
easy10 minReport the text of the list's first child element.
- 3
Read the next sibling
easy10 minReport the text of the item after the middle one.
- 4
Walk up with closest
easy10 minFrom the span, find the nearest card and report its class.
- 5
Handle a missing sibling
medium10 minReport a message when the item has nothing after it.
Find the bug(5)
- 1
Fix childNodes used for the first child
easy8 minchildNodes includes whitespace, so the first one is a text node.
- 2
Fix nextSibling used for an element
easy8 minnextSibling can land on whitespace between the tags.
- 3
Fix the previous sibling used
easy8 minThe item after the middle one is wanted, not the one before it.
- 4
Fix querySelector used to walk up
easy8 minquerySelector searches downwards; closest searches upwards.
- 5
Fix parentNode used where the id is needed
easy8 minThe parent of the span is the paragraph, not the card.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace