JavaScript Array push and pop — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Array push and pop 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
Add to the end
easy10 minPush two names onto a list and show it joined by commas.
- 2
Remove from the end
easy10 minPop the last value off and show the value that was removed.
- 3
Add to the front
easy10 minUnshift a value onto the front and show the list joined by commas.
- 4
Remove from the front
easy10 minShift the first value off and show what is left, joined by commas.
- 5
Use the return value of push
medium10 minShow the new length that push gives back.
Find the bug(5)
- 1
Fix push used as if it returned the array
easy8 minpush returns the new length, not the array.
- 2
Fix pop used to add
easy8 minpop removes a value; it does not accept one.
- 3
Fix shift used instead of unshift
easy8 minThe value should be added to the front, not removed from it.
- 4
Fix the wrong end removed
easy8 minThe last value should go, but the first one is being taken.
- 5
Fix the original being changed
easy8 minPushing onto the original list changes it; only the copy should grow.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace