Stand In Line javaScript Exercise ! Stuck!

Stand In Line javaScript Exercise ! Stuck!


Wow, i did a quick skip through a few posts, and just decided to erase the whole code since my complicated code only didn’t satisfy 1 condition. Before i used shift, push, pop and length methods in a simple way, but that didn’t lead me past the exercise, still only satisfied 3 conditions. Then I decided to use an if loop, which did the same result. This quick skip made me only use 2 methods (push and shift). I was confused about that line change, didn’t understand the json part also. Man there’s so much to learn, i’m really out of this league. But still i’m glad i passed this exercise since i was stuck for several days. Thanks people!


How about doing it like this

function nextInLine(arr, item) {
// Your code here

item = arr.shift();
return item; // Change this line


Perhaps using precise language in the instruction would help…


Lol, I was stuck because i did my own “array” inside the function arr = (1,2,3,4,5); but I just follow the steps on this post and boom! i got it!



Thank you!
Seriously I thought I was losing my mind. After 173 exercises, most of which were more or less straightforward, all of a sudden I thought I had skipped 20 steps somehow.
I gotta hand it to them, they have done a really fantastic job of being concise and still getting the point across up until now. But once I wrap my mind around what they are trying to say here, I would LOVE to (try to) help with the wording.

Edit: I’m sorta new at these forums, sorry if I did this reply wrong.


I finally got past this step but I’m going to nitpick on a couple of things, because I’m a horrible selfish person and doing this will help me remember what I learned. Yes, I can only remember things by making a big stink about something. Sorry! :smiling_imp:

First of all, the previous 172 exercises have taught me that it is important to read and pay attention to every single word on the screen. The fact that each lesson is so brief makes each word that much more important to pay attention to. Even the commented code is not to be ignored. Therefore, I was confused and troubled that this comment did not mean what it seemed to mean:

I thought it was telling me to modify that line of code in order to test the function. Previous exercises did require changes to the console.log line, right? Hmmm…

Then, in the blank area under the Reset | Help | Bug buttons, after hitting “Run” the first time, I see the following test cases:

Now, after deciding to set this aside until later, and getting the exercise to work, and seeing that the test cases all work after the exercise is done correctly, I can retrospectively understand that we are probably supposed to ignore this area. But try telling that to someone who is struggling with this exercise and looking everywhere for clues. It’s really confusing! :cold_sweat:

Wait. I’m not done yet.

When I read the title of this page, “Stand in Line,” and then read about queues and data structure, I could not tell if this was a new thing that functions can do? Is this a new topic? Are we going to be writing code that looks like function arr.queue(); ?

Now that I know what it is, I think that the concept of a queue and data structure (in my opinion) probably should have been introduced along with arrays in the first place. It makes a lot of sense to me that arrays would/should be kept in order.

So, the conclusion of my tiresome essay is, there were several factors that contributed to making this particular exercise especially confusing to me, and I don’t think it needed to be. A teeny tiny little hint - well, more than what was there - that this is like, a review/practice step, or something like that? Make the title a different color, perhaps?

I know there are plenty of people who probably thought this was a piece of cake, totes OBV, fer sher, so if you think I’m just obtuse, please just try to be tolerant. Thank you. :hugging:


I’m having this same problem. I wrote it first without help and only the middle two are showing up as correct, and the error arr.push is not a function shows up.

function nextInLine(arr, item) {
// Your code here

return arr.shift(); // Change this line

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(10, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));


If you strip out all the comments, it somehow works. I copied and pasted an answer someone said worked in here, and all the errors are gone. I think it’s a bug. Going to report it.

That was NOT fun though as I literally sat here for half an hour trying to figure out what could be wrong, when it was the same as other people’s answers.


i’m slightly confused at this one.

i’ve read through the thread, i believe I grasp the purpose and use of .shift and .push

with the function below, objectives 1,2 and 4 come back green, so that’s good.
the 3rd one stay red though, even though the console returns the “5” im asked for.
I don’t know what i’m doing wrong, please enlighten me!

function nextInLine(arr, item) {
return testArr.shift();

var testArr = [5,6,7,8,9];

console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 1));
console.log("After: " + JSON.stringify(testArr));


You have an argument in your function called arr which you are not using. You can either:

  • Change all instances of testArr to arr inside your nexInLine function


  • Replace the argument name arr with testArr in your function nextInLine



that’s really all it was!

it works just fine now : )

thank you very much for your quick reply!


I quite agree. The way this exercise was written out was not as clear and concise as it could have been. Thankfully we have a very helpful community here!


Is there any way we can change the wording of the question to make it clear what to change in that last area? There are no instructions on how to use that test area, and at this point not everyone will understand what to change, and that the testing code isn’t even necessary to get a correct answer.


Just for the sake of writing it, here’s a nice solution:

function nextInLine(arr, value){
  return arr.push(value) && arr.shift();


You should be using pop and unshift for Stand in line

// Array before function 
var testArr = [1,2,3,4,5];

function nextInLine(arr, item) {
  return arr.shift();

// Function takes 1st number off and adds a number to the end 

// Display Code
 // JSON.stringify is a method to show an array inside of a string
 // JSON.stringify = string interpolation for arrays

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

console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log(nextInLine(testArr, 7)); // Modify this line to test
console.log(nextInLine(testArr, 8)); // Modify this line to test

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

// Please place code between three ticks (the key below esc)


The checklist threw me off soooo hard!


This is the correct…u got correct result

function nextInLine(arr, item) {
// Your code here
return arr.push(item) && arr.shift();
// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));


Hey how you doing? Great primer btw. Say Chad, you mentioned “validator”. What is the validator that you are referring to?
Appreciate the feedback.
Peace and happy coding!


the “validator” I am referring to is the tests that FCC runs on you answer to see if it is right.