Elyses Enchantments - Task 3

Hi!

I have an issue with “Task 3”; it says to insert a card at the top of the stack for which I used “unshift” method, but I didn’t pass the test. Then I noticed in “Hints and Tips” the following: " There is a [built-in] method to add a new value to the end of the array."

So is it my mistake, is it top or end of the array? Thank you!

Typically when an array is used to represent a stack, the top of the stack is the end of the array.

1 Like

The example clears up the ambiguity:

const newCard = 8;
insertItemAtTop([5, 9, 7, 1], newCard);
// => [5, 9, 7, 1, 8]

The tests expect the new value at the end of the array. unshift adds a new value to the start of the array.

3 Likes

Well, I feel properly stupid now :see_no_evil:, thanks guys :)!

2 Likes

You won’t believe how many of those moments I have after 35+ years of coding…

3 Likes

It really makes me feel a little better to hear it, so thank you :)!