Report the id of the paragraph's parent.
Acceptance criteria
- 1.#out should show box.
JavaScript Tutorial · JavaScript DOM
These 10 tasks go with the JavaScript DOM Traversal chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “DOM traversal moves from one element to its parent, children or siblings.” .
1.Find the parentexercise · easy · 10 min
Report the id of the paragraph's parent.
Passes when: #out should show box.
2.Read the first childexercise · easy · 10 min · practice plan
Report the text of the list's first child element.
Passes when: #out should show A.
3.Read the next siblingexercise · easy · 10 min · practice plan
Report the text of the item after the middle one.
Passes when: #out should show C.
4.Walk up with closestexercise · easy · 10 min · practice plan
From the span, find the nearest card and report its class.
Passes when: #out should show card.
5.Handle a missing siblingexercise · medium · 10 min · practice plan
Report a message when the item has nothing after it.
Passes when: #out should show no sibling.
6.Fix childNodes used for the first childbug fix · easy · 8 min
childNodes includes whitespace, so the first one is a text node.
Passes when: #out should show item A.
7.Fix nextSibling used for an elementbug fix · easy · 8 min · practice plan
nextSibling can land on whitespace between the tags.
Passes when: #out should show next is C.
8.Fix the previous sibling usedbug fix · easy · 8 min · practice plan
The item after the middle one is wanted, not the one before it.
Passes when: #out should show C.
9.Fix querySelector used to walk upbug fix · easy · 8 min · practice plan
querySelector searches downwards; closest searches upwards.
Passes when: #out should show card.
10.Fix parentNode used where the id is neededbug fix · easy · 8 min · practice plan
The parent of the span is the paragraph, not the card.
Passes when: #out should show card.
Between them these tasks cover parentElement, siblings and closest.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.