Basic JavaScript - Stand in Line

Im having problems with the javascript stand in line section. my code seems like it does what it is supposed to.

  // Only change code below this line
let x = arr[0];
  arr.push(item);
  arr.shift();
  return x
  // Only change code above this line
}

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


```javascript
function nextInLine(arr, item) {
  // Only change code below this line
let x = arr[0];
  arr.push(item);
  arr.shift();
  return x
  // Only change code above this line
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0

Challenge: Basic JavaScript - Stand in Line

Link to the challenge:

the first test you are failing is this one

Failed:nextInLine([], 5)

Notice how the test gives the nextInLine function an empty array?
What happens when your code sees an empty array and tries to complete this line of code?
let x = arr[0] ?

I looked it up on google and didnt know shift returned the value removed so i got it to pass. it seems like the above code works fine too though

except it would fail fail on, if your code was checked against something this nextInLine([], 5), as hbar1st pointed it out, happy learning :slight_smile: