Stand in Line Help needed JavaScript

Stand in Line Help needed JavaScript
0.0 0

#1

**Can anyone pls tell me where is the problem in the code:
and can anyone pls share the correct code with a bit explanation. I am stuck here for a while.
it would be a great help.
**

Your code so far


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

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine([5,6,7,8,9], 1); // 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/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/


#2

FIRST HINT:

Taken from MDN - Array.prototype.shift

The shift() method removes the first element from an array and returns that removed element.

Taken from challenge instruction:

The nextInLine function should then return the element that was removed.

SECOND HINT:
When you’re inside a function you usually manipulate the object passed to that function; you do that through the parameters ( the stuff into the parenthesis next to the name of the function ).
Arr is the parameter you want to use, but in your code that variable is assigned the testArr value. which mess up the things a bit. Just remove that assignment and use arr for your operations ( which are the correct ones).

If you can’t manage to solve it you can watch the solution below ( but i’ll strongly suggest to keep trying, you’re really close ^^):

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