# Stand in line challenge

**URL:** <https://forum.freecodecamp.org/t/stand-in-line-challenge/176508>\
**Category:** General\
**Created:** [February 24, 2018, 11:31pm UTC](https://forum.freecodecamp.org/t/stand-in-line-challenge/176508 "2018-02-24T23:31:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![1ncontr0L](https://avatars.discourse-cdn.com/v4/letter/1/bbe5ce/32.png) [@1ncontr0L](https://forum.freecodecamp.org/u/1ncontr0L)\
**Post date:** [February 24, 2018, 11:31pm UTC](https://forum.freecodecamp.org/t/stand-in-line-challenge/176508/1 "2018-02-24T23:31:33Z")

</div>

![array](https://global.discourse-cdn.com/freecodecamp/original/3X/d/c/dc911edf0478f0dd6b27e9dffbb0e81837fc3f04.JPG)

Okay guys, now look at this picture and please correct me if im mistaken. I solved it with a bit of help, but i dont know if i understand it: If you look at the instructions, it means to push an item… so now we have 1 arr, and two items (arr, item, item), and after that, we have to shift the first element of an array, which makes it ‘‘arr’’, so now we have (item, item), we have two items, and no arrs, is that it?

---

<div class="post-metadata">

**Author:** ![JohnnyBizzel](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/johnnybizzel/32/37661_2.png) [@JohnnyBizzel](https://forum.freecodecamp.org/u/JohnnyBizzel)\
**Post date:** [February 25, 2018, 12:25pm UTC](https://forum.freecodecamp.org/t/stand-in-line-challenge/176508/3 "2018-02-25T12:25:06Z")

</div>

`push` adds an item to the end of the array and `shift` removes one from the front (1st element) I believe.

[Read the docs if you are still not sure](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)

[My solution to the problem](https://jsfiddle.net/968zu87f/4/)

---

<div class="post-metadata">

**Author:** ![1ncontr0L](https://avatars.discourse-cdn.com/v4/letter/1/bbe5ce/32.png) [@1ncontr0L](https://forum.freecodecamp.org/u/1ncontr0L)\
**Post date:** [February 28, 2018, 5:38pm UTC](https://forum.freecodecamp.org/t/stand-in-line-challenge/176508/4 "2018-02-28T17:38:39Z")

</div>

![mystery](https://global.discourse-cdn.com/freecodecamp/original/3X/7/1/718eef2ce011841b985b2b37b6da268e33d11447.JPG)

See this is the correct answer, but I dont get it…What is arr anyway? its a argument aint it? so why cant i put nextInLine,push(), or item.push(), instead of arr.push()… why arr? arr is the same as item to me, so why cant i assign item,push()… This really confuses me, And as it goes for the answer on the left, i have no idea what is going on, and what is ‘‘JSON.stringify’’ anyway… i google it a bit, but i havent done a single order on this site, and it just shows up from nowhere… :S

---

<div class="post-metadata">

**Author:** ![JohnnyBizzel](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/johnnybizzel/32/37661_2.png) [@JohnnyBizzel](https://forum.freecodecamp.org/u/JohnnyBizzel)\
**Post date:** [February 28, 2018, 7:14pm UTC](https://forum.freecodecamp.org/t/stand-in-line-challenge/176508/5 "2018-02-28T19:14:42Z")

</div>

I think if you ask these questions on the gitter channel you will get answers quicker.  
Many questions! [https://gitter.im/FreeCodeCamp/Help](https://gitter.im/FreeCodeCamp/Help)

Note. `JSON.stringify` helps present the data better in the output by turning the object to a string. Otherwises it would appear as `[object Object]`

---

<div class="post-metadata">

**Author:** ![lionel-rowe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lionel-rowe/32/41877_2.png) [@lionel-rowe](https://forum.freecodecamp.org/u/lionel-rowe)\
**Post date:** [February 28, 2018, 7:31pm UTC](https://forum.freecodecamp.org/t/stand-in-line-challenge/176508/6 "2018-02-28T19:31:49Z")

</div>

You pass parameters into a function as arguments and it returns a value.

```javascript
function divide(arg1, arg2) {
  var myVal = arg1 / arg2;
  return myVal;
}

var param1 = 10;
var param2 = 5;

divide(param1, param2);
// returns 2

```

Note that parameters can just as easily be arrays, strings, or objects. In your case, the first parameter is an array, and the second is a number.

---

<div class="post-metadata">

**Author:** ![Reinoud-Zuyderhoff](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/reinoud-zuyderhoff/32/80792_2.png) [@Reinoud-Zuyderhoff](https://forum.freecodecamp.org/u/Reinoud-Zuyderhoff)\
**Post date:** [February 28, 2018, 7:49pm UTC](https://forum.freecodecamp.org/t/stand-in-line-challenge/176508/7 "2018-02-28T19:49:48Z")

</div>

I’m not much further down the road then you, so maybe I’m wrong. ‘arr’ is an Array, the .push() function can put an ‘item’ in there using array.push(item). Trying to put item.push() is like trying to stuff a turkey with another turkey 😁. Shoving an entire function in the will get complicated as well, I think, maybe it’s useful down the road.

---

<div class="post-metadata">

**Author:** ![1ncontr0L](https://avatars.discourse-cdn.com/v4/letter/1/bbe5ce/32.png) [@1ncontr0L](https://forum.freecodecamp.org/u/1ncontr0L)\
**Post date:** [March 1, 2018, 4:45pm UTC](https://forum.freecodecamp.org/t/stand-in-line-challenge/176508/8 "2018-03-01T16:45:44Z")

</div>

arr just stands for an array? because in my function (arr & item) are just parameters, waiting to be declared

---

<div class="post-metadata">

**Author:** ![DanCouper](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/dancouper/32/158608_2.png) [@DanCouper](https://forum.freecodecamp.org/u/DanCouper)\
**Post date:** [March 1, 2018, 5:00pm UTC](https://forum.freecodecamp.org/t/stand-in-line-challenge/176508/9 "2018-03-01T17:00:29Z")

</div>

Yes: it could be called `djcbrdicjdjfjdodjfjrj` or `foobar`, but it’s just called `arr` because that’s a better name for a parameter that will be an array

`nextInLine` is the function itself, you can’t push to that, and `item` is the item you’re pushing into the array, you can’t push it into itself.

---

<div class="post-metadata">

**Author:** ![PortableStick](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/portablestick/32/65591_2.png) [@PortableStick](https://forum.freecodecamp.org/u/PortableStick)\
**Post date:** [March 1, 2018, 5:21pm UTC](https://forum.freecodecamp.org/t/stand-in-line-challenge/176508/10 "2018-03-01T17:21:40Z")

</div>

> [@1ncontr0L](#):
>
> because in my function (arr & item) are just parameters, waiting to be declared

You’re close. They’re not waiting to be declared, they’re waiting to be assigned a value, which is what I think you meant. But you’re correct that `arr` and `item` don’t have any meaning by themselves. `arr` isn’t an array just because of its name, but because of what gets passed **when the function is called**.

If you do this

```javascript
// call the function with arguments
nextInLine([1,2,3], 4);

```

Then `arr` will be the array `[1,2,3]` and `item` will be the number 4. But if we switch the order

```auto
nextInLine(4, [1,2,3])

```

then `arr` will refer to the number 4 and `item` will be the array `[1,2,3]`. If you try this you’ll get an error and the code won’t work.

Another piece of the puzzle that you may be missing is that objects can have functions attached to them which are _specific to the type of data it holds_. When a function is attached to an object in this way, we tend to call them _methods_, but don’t get too hung up on that. For instance, the array `[1,2,3]` has the method `push` which takes an item and adds it to the end of the array **that you called the method on**. For example

```auto
[1,2,3].push(4) // [1,2,3,4]

```

Since this array wasn’t in a variable, it doesn’t get saved and so is tossed into the void, never to be seen again. Let’s save it.

```auto
var arr = [1,2,3];
// methods work when the data is stored in a variable
arr.push(4);
console.log(arr); // [1,2,3,4]

```

If you try to call an array specific method on something that isn’t an array, you’ll get an error and your program will crash.

```auto
var item = 4;
item.push(4); // TypeError: 4.push is not a function

```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:25pm UTC](https://forum.freecodecamp.org/t/stand-in-line-challenge/176508/11 "2021-01-17T20:25:34Z")

</div>

Closed on January 17, 2021, 8:25pm UTC


