Stand in Line - Help please

Tell us what’s happening:
I don’t know how to solve that challenge. I’m really stucked here. Help, please.

Your code so far


function nextInLine(arr, item) {
  // Your code here
  
  return item;  // Change this line
}

// 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));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/stand-in-line

Your code needs to do two things:

  1. Add a number to the end of an array.
  2. Remove an item from the beginning of the array, then return it.

You should know how to do all of these things from previous lessons:

Manipulate arrays with push
Manipulate arrays with shift

How do you combine this knowledge to write the function you need?

I don’t know, that’s the problem. That’s what i’m typing:

function nextInLine(arr, item) {
// Your code here
testArr.push(6);
return item; // Change this line
}

// 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));

But the console is giving me some errors:

// running test
nextInLine([2], 1) should return 2
nextInLine([5,6,7,8,9], 1) should return 5
After nextInLine(testArr, 10), testArr[4] should be 10
// tests completed

I’m also stuck on this. any luck???

Let’s think about what the code above does.

The following line

  testArr.push(6);

adds the number 6 to the end of testArr. You are not supposed to push the number 6 onto testArr. You are supposed to push item onto arr (see the instructions below):

Write a function nextInLine which takes an array (arr) and a number (item) as arguments.

Add the number to the end of the array, then remove the first element of the array.

The nextInLine function should then return the element that was removed.
Your next line:

  return item;  // Change this line

just returns item (the number passed into the function). To solve this challenge you will need to use push and shift.

Hint: Your first line is almost correct. You need to completely change the return statement so that it removes the first item in arr (see shift) and then returns it. Read the documentation for shift to see what value it returns when called.