Skip to main content

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

    Add to the end

    easy10 min

    Push two names onto a list and show it joined by commas.

  2. 2

    Remove from the end

    easy10 min

    Pop the last value off and show the value that was removed.

  3. 3

    Add to the front

    easy10 min

    Unshift a value onto the front and show the list joined by commas.

  4. 4

    Remove from the front

    easy10 min

    Shift the first value off and show what is left, joined by commas.

  5. 5

    Use the return value of push

    medium10 min

    Show the new length that push gives back.

Find the bug(5)

  1. 1

    Fix push used as if it returned the array

    easy8 min

    push returns the new length, not the array.

  2. 2

    Fix pop used to add

    easy8 min

    pop removes a value; it does not accept one.

  3. 3

    Fix shift used instead of unshift

    easy8 min

    The value should be added to the front, not removed from it.

  4. 4

    Fix the wrong end removed

    easy8 min

    The last value should go, but the first one is being taken.

  5. 5

    Fix the original being changed

    easy8 min

    Pushing 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