# I do not understand stand in line

**URL:** <https://forum.freecodecamp.org/t/i-do-not-understand-stand-in-line/475930>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [August 30, 2021, 6:39pm UTC](https://forum.freecodecamp.org/t/i-do-not-understand-stand-in-line/475930 "2021-08-30T18:39:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![shiripindayeukai](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/shiripindayeukai/32/230749_2.png) [@shiripindayeukai](https://forum.freecodecamp.org/u/shiripindayeukai)\
**Post date:** [August 30, 2021, 6:39pm UTC](https://forum.freecodecamp.org/t/i-do-not-understand-stand-in-line/475930/1 "2021-08-30T18:39:11Z")

</div>

**Tell us what’s happening:**  
Describe your issue in detail here.  
I have managed to solve the challenge below by myself but it was after numerous attempts and even at that my understanding is still hazy. I am looking for pointers on where i can read more on this .Thanks in advance to those willing to help.

```
  **Your code so far**

```

```js

function nextInLine(arr, item) {
// Only change code below this line

return item;
// Only change code above this line

}

// Setup
var testArr = [1,2,3,4,5];

// Display code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6));
console.log("After: " + JSON.stringify(testArr));

```

```
  **Your browser information:**

```

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36`

**Challenge:** Stand in Line

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/stand-in-line)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![bbsmooth](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bbsmooth/32/203556_2.png) [@bbsmooth](https://forum.freecodecamp.org/u/bbsmooth)\
**Post date:** [August 30, 2021, 6:46pm UTC](https://forum.freecodecamp.org/t/i-do-not-understand-stand-in-line/475930/2 "2021-08-30T18:46:00Z")

</div>

You didn’t include your actual solution so we can’t comment on what you did. Can you be a little more specific about what you don’t understand?

---

<div class="post-metadata">

**Author:** ![Sylvant](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sylvant/32/254977_2.png) [@Sylvant](https://forum.freecodecamp.org/u/Sylvant)\
**Post date:** [August 30, 2021, 8:43pm UTC](https://forum.freecodecamp.org/t/i-do-not-understand-stand-in-line/475930/3 "2021-08-30T20:43:54Z")

</div>

the challenge is very straight-forward on what you should do and in what order to achieve it, its hard to tell at which point you fail to understand it.  
Are you well familiar how functions behave? Are you familiar with the `return` action in functions and how it works? Are you comfortable with manipulating arrays, push new elements at their end and remove existing ones, say from their start? Those are few things which are part of the challenge.  
The code which is beneath the `// Setup` comment has the purpose to display on the console how the `testArr` is changed, after its being the subject of the `nextLine` function. In the current example, the function should add 6 on the array end and remove its first element(1). Hope that helps

---

<div class="post-metadata">

**Author:** ![shiripindayeukai](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/shiripindayeukai/32/230749_2.png) [@shiripindayeukai](https://forum.freecodecamp.org/u/shiripindayeukai)\
**Post date:** [August 31, 2021, 7:22am UTC](https://forum.freecodecamp.org/t/i-do-not-understand-stand-in-line/475930/4 "2021-08-31T07:22:27Z")

</div>

Hi @bbsmooth my solution was as follows 🙂

```auto
function nextInLine(arr, item) {

  // Only change code below this line

  arr.push(item);

  var removed = arr.shift();

  return removed;

  // Only change code above this line

  

}

// Setup

var testArr = [1,2,3,4,5];

// Display code

console.log("Before: " + JSON.stringify(testArr));

console.log(nextInLine(testArr, 6));

console.log("After: " + JSON.stringify(testArr));

```

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [August 31, 2021, 7:38am UTC](https://forum.freecodecamp.org/t/i-do-not-understand-stand-in-line/475930/5 "2021-08-31T07:38:21Z")

</div>

I edited your post to include `[spoiler]` tags since it is a working solution.

* * *

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (’).

---

<div class="post-metadata">

**Author:** ![snowmonkey](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/snowmonkey/32/241579_2.png) [@snowmonkey](https://forum.freecodecamp.org/u/snowmonkey)\
**Post date:** [August 31, 2021, 11:59am UTC](https://forum.freecodecamp.org/t/i-do-not-understand-stand-in-line/475930/6 "2021-08-31T11:59:04Z")

</div>

Your solution is exactly right. To add or remove from the tail of an array, we push items on or pop items off. You did this exactly right.

To add or remove from the front of an array, we shift things on or unshift them off. And, when we use the unshift function, that _returns_ (passes back) the thing we’ve removed. And you are catching the return value in a variable.

Array functions take some practice, but you’ve done well here!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [March 1, 2022, 11:59pm UTC](https://forum.freecodecamp.org/t/i-do-not-understand-stand-in-line/475930/7 "2022-03-01T23:59:56Z")

</div>

Closed on March 1, 2022, 11:59pm UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
