Stand in Line i'm not understand with the flow in the code below

Stand in Line i'm not understand with the flow in the code below
0

Tell us what’s happening:

Your code so far


function nextInLine(arr, item) {
  // Your code here
  
  return item;
  return remove;  // Change this line
  arr.push(item);
 var remove = arr.shift();
}


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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 2)); // Modify this line to test
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/76.0.3809.100 Safari/537.36.

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

As soon as the code in your function reaches a return statement, the function stops. This is explained in a later challenge (https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/return-early-pattern-for-functions/).

So, after your line: return item; the function stops and returns to the line where the function was called (console.log(nextInLine(testArr, 2));). Which is not what you intend.

Your idea is good, however, just the order is not. If you remove the line that returns item and move the line that returns remove to the end of the function, you should see it starts to work.