Skip to main content

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. 1

    Remove an element

    easy10 min

    Remove the paragraph and report how many are left in the box.

  2. 2

    Empty an element

    easy10 min

    Clear everything inside the list and report how many items remain.

  3. 3

    Remove several elements

    easy10 min

    Remove every element with the class old and report how many paragraphs are left.

  4. 4

    Guard a missing element

    easy10 min

    Only remove the element if it was actually found, then report a message.

  5. 5

    Put an element back

    medium10 min

    Remove the paragraph then append it again, and report how many are in the box.

Find the bug(5)

  1. 1

    Fix remove called on the parent

    easy8 min

    The paragraph should go, not the whole box.

  2. 2

    Fix remove used without brackets

    easy8 min

    remove is a method and must be called.

  3. 3

    Fix the unguarded removal

    easy8 min

    A missing element gives null, and calling remove on it would throw.

  4. 4

    Fix the text cleared instead of the elements

    easy8 min

    Setting textContent leaves no elements, but the wrong thing was targeted.

  5. 5

    Fix the wrong class removed

    easy8 min

    The 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