Append a new item and report the text of the last one.
Acceptance criteria
- 1.#out should show Last.
JavaScript Tutorial · JavaScript DOM
These 10 tasks go with the JavaScript Inserting 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: “append, prepend, before and after decide exactly where a new element lands.” .
1.Add to the endexercise · easy · 10 min
Append a new item and report the text of the last one.
Passes when: #out should show Last.
2.Add to the startexercise · easy · 10 min · practice plan
Prepend a new item and report the text of the first one.
Passes when: #out should show First.
3.Insert as a siblingexercise · easy · 10 min · practice plan
Put a paragraph after the box and report how many children the box has.
Passes when: #out should show 1.
4.Append textexercise · easy · 10 min · practice plan
Append the text and end to the paragraph, then report the whole thing.
Passes when: #out should show Start and end.
5.Move an existing elementexercise · medium · 10 min · practice plan
Move the first item to the end and report the last item's id.
Passes when: #out should show a.
6.Fix append used where prepend is neededbug fix · easy · 8 min
The item should go to the front of the list.
Passes when: #out should show First.
7.Fix after used where append is neededbug fix · easy · 8 min · practice plan
The item landed beside the list instead of inside it.
Passes when: #out should show 2.
8.Fix the element copied instead of movedbug fix · easy · 8 min · practice plan
Appending an existing element moves it, so no clone is needed.
Passes when: #out should show 2.
9.Fix insertAdjacentHTML at the wrong positionbug fix · easy · 8 min · practice plan
The new item should go first, not last.
Passes when: #out should show First.
10.Fix the two items added separately as one stringbug fix · easy · 8 min · practice plan
Two elements should be added, not one holding both names.
Passes when: #out should show 2.
Between them these tasks cover append, prepend and before and after.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.