JavaScript Removing Elements — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Removing Elements 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
Remove an element
easy10 minRemove the paragraph and report how many are left in the box.
- 2
Empty an element
easy10 minClear everything inside the list and report how many items remain.
- 3
Remove several elements
easy10 minRemove every element with the class old and report how many paragraphs are left.
- 4
Guard a missing element
easy10 minOnly remove the element if it was actually found, then report a message.
- 5
Put an element back
medium10 minRemove the paragraph then append it again, and report how many are in the box.
Find the bug(5)
- 1
Fix remove called on the parent
easy8 minThe paragraph should go, not the whole box.
- 2
Fix remove used without brackets
easy8 minremove is a method and must be called.
- 3
Fix the unguarded removal
easy8 minA missing element gives null, and calling remove on it would throw.
- 4
Fix the text cleared instead of the elements
easy8 minSetting textContent leaves no elements, but the wrong thing was targeted.
- 5
Fix the wrong class removed
easy8 minThe elements to keep are being taken off instead.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace