Confused about Stand in Line challenge from JS

Confused about Stand in Line challenge from JS


I read this hint over here: freeCodeCamp Challenge Guide: Stand In Line
And im really confused what do they mean by
"Use an array function you learned to add the item to the end of the array arr." and
"Use an array function you learned to remove the first element from array arr."
What element of array arr are they talking about? These explanations make no sanse imo.


Maybe it is a confusion over terms. In an array, the elements are the things that are in the array. In :

let arr = [ 1, 4, 9 ];

The numbers are the elements.

If I wanted to add an element, I could use the array prototype method (function) push to add one.


Now the array is [1, 4, 9, 16]. If I wanted to remove the first element, I would go:


Now it is [4, 9, 16].

The object Array (the type that all arrays are) have several built in useful methods (functions attached to the object/array). You can read up on them here.

They can be a little confusing at first (especially if callback functions are new to you, which some of them use) but they are very useful.

Let us know if anything else is still confusing.


With this challenge you are a writing a function that gets two parameters arr and item.
The item that is mentioned in the instructions is this parameter item which you are to
add to the end of arr which is also passed to the function.
The second instruction is also talking about the arr parameter inside the function.


The code that solved the challenge are the three lines below. I understand lines 1 and 2, but I don’t at all understand line 3. Please help

  • Line 1 - testArr.push(item);
  • Line 2 - testArr.shift();
  • Line 3 - return arr[0] || item;


I am unable to understand the use of item in the push element and how come item is referred as the array.
Can anyone please explain?



I’m not sure I understand your question, but I’ll try to answer it. In JavaScript, certain data types have built in methods (functions). One of these for the array type is push. It adds an element to end of the array. So:

let myArr = [1, 2, 3]

// [1, 2, 3]


// [1, 2, 3, 4]

Does that make it clearer?


I just did this, nothing complicated and it works. I used a hint form a year ago. Most of those replies don’t work. LOL I know : I tried most of them. So this is it. Don’t let the console logs confuse you. That is their thing and we aren’t there yet.