Push two names onto a list and show it joined by commas.
Acceptance criteria
- 1.#out should show Ada,Grace,Alan.
JavaScript Tutorial · JavaScript Arrays
These 10 tasks go with the JavaScript Array push and pop 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: “JavaScript push, pop, shift and unshift add and remove elements at the ends of an array.” .
1.Add to the endexercise · easy · 10 min
Push two names onto a list and show it joined by commas.
Passes when: #out should show Ada,Grace,Alan.
2.Remove from the endexercise · easy · 10 min · practice plan
Pop the last value off and show the value that was removed.
Passes when: #out should show Mango.
3.Add to the frontexercise · easy · 10 min · practice plan
Unshift a value onto the front and show the list joined by commas.
Passes when: #out should show one,two,three.
4.Remove from the frontexercise · easy · 10 min · practice plan
Shift the first value off and show what is left, joined by commas.
Passes when: #out should show b,c.
5.Use the return value of pushexercise · medium · 10 min · practice plan
Show the new length that push gives back.
Passes when: #out should show 4.
6.Fix push used as if it returned the arraybug fix · easy · 8 min
push returns the new length, not the array.
Passes when: #out should show Ada,Grace.
7.Fix pop used to addbug fix · easy · 8 min · practice plan
pop removes a value; it does not accept one.
Passes when: #out should show a,b,c.
8.Fix shift used instead of unshiftbug fix · easy · 8 min · practice plan
The value should be added to the front, not removed from it.
Passes when: #out should show one,two,three.
9.Fix the wrong end removedbug fix · easy · 8 min · practice plan
The last value should go, but the first one is being taken.
Passes when: #out should show Apple,Banana.
10.Fix the original being changedbug fix · easy · 8 min · practice plan
Pushing onto the original list changes it; only the copy should grow.
Passes when: #out should show kept 2.
Between them these tasks cover push, pop, shift and unshift.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.