Create a paragraph, put it in the box, and report how many exist.
Acceptance criteria
- 1.#out should show 1.
JavaScript Tutorial · JavaScript DOM
These 10 tasks go with the JavaScript Creating 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: “createElement builds a new element that can then be added to the page.” .
1.Create and attach an elementexercise · easy · 10 min
Create a paragraph, put it in the box, and report how many exist.
Passes when: #out should show 1.
2.Set content before attachingexercise · easy · 10 min · practice plan
Create a button with the text Save and report its text.
Passes when: #out should show Save.
3.Build a list in a loopexercise · easy · 10 min · practice plan
Create one list item per name and report how many were made.
Passes when: #out should show 3.
4.Set a class on a new elementexercise · easy · 10 min · practice plan
Create a div with the class card and report its class.
Passes when: #out should show card.
5.Clone an elementexercise · medium · 10 min · practice plan
Clone the row and report how many rows there are afterwards.
Passes when: #out should show 2.
6.Fix the element never attachedbug fix · easy · 8 min
A created element is invisible until it is appended.
Passes when: #out should show 1.
7.Fix the tag written with bracketsbug fix · easy · 8 min · practice plan
createElement takes a tag name, not markup.
Passes when: #out should show made a p.
8.Fix the element created outside the loopbug fix · easy · 8 min · practice plan
One element is being reused, so only the last name survives.
Passes when: #out should show 3.
9.Fix the shallow clonebug fix · easy · 8 min · practice plan
cloneNode without true copies the element but not its contents.
Passes when: #out should show One.
10.Fix append called on the new elementbug fix · easy · 8 min · practice plan
The new element is being appended to itself instead of the box.
Passes when: #out should show 1.
Between them these tasks cover createElement, append and cloneNode.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.