Remove the paragraph and report how many are left in the box.
Acceptance criteria
- 1.#out should show 0.
JavaScript Tutorial · JavaScript DOM
These 10 tasks go with the JavaScript Removing Elements 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: “remove takes an element off the page, and removeChild does the same from the parent.” .
1.Remove an elementexercise · easy · 10 min
Remove the paragraph and report how many are left in the box.
Passes when: #out should show 0.
2.Empty an elementexercise · easy · 10 min · practice plan
Clear everything inside the list and report how many items remain.
Passes when: #out should show 0.
3.Remove several elementsexercise · easy · 10 min · practice plan
Remove every element with the class old and report how many paragraphs are left.
Passes when: #out should show 1.
4.Guard a missing elementexercise · easy · 10 min · practice plan
Only remove the element if it was actually found, then report a message.
Passes when: #out should show nothing to remove.
5.Put an element backexercise · medium · 10 min · practice plan
Remove the paragraph then append it again, and report how many are in the box.
Passes when: #out should show 1.
6.Fix remove called on the parentbug fix · easy · 8 min
The paragraph should go, not the whole box.
Passes when: #out should show box is still here.
7.Fix remove used without bracketsbug fix · easy · 8 min · practice plan
remove is a method and must be called.
Passes when: #out should show 0.
8.Fix the unguarded removalbug fix · easy · 8 min · practice plan
A missing element gives null, and calling remove on it would throw.
Passes when: #out should show nothing to remove.
9.Fix the text cleared instead of the elementsbug fix · easy · 8 min · practice plan
Setting textContent leaves no elements, but the wrong thing was targeted.
Passes when: #out should show 0.
10.Fix the wrong class removedbug fix · easy · 8 min · practice plan
The elements to keep are being taken off instead.
Passes when: #out should show 2.
Between them these tasks cover remove, removeChild and Clearing content.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.