Queue challenge

I did exactly the same thing as the solution and it keeps telling me that arr.shift is not a function, like this: TypeError: arr.shift is not a function. I don’t know what to do. Here’s my code:

function nextInLine(arr, item) {
  // Only change code below this line
  arr = 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));
1 Like

I moved your question to its own topic because you were asking a question related to your own code for a challenge and were not answering the OP of the other thread. It is always best to create your own thread for you specific question(s). Also, it is advisable to use the Ask for Help button on the challenge, so it auto-populates with your current code and the challenge url.

Thank you.

1 Like

You get the error that arr,shift() is not a function because at this point of the code arr is a number
this comes from this line:

because push changes the array, but returns the new length, so arr there becomes the length of the array after push, which is a number

how could you fix that?

Thank you, I’m sorry, I hadn’t really understood how it works.