Stand in Line (i need to figure this out to continue learning )

Tell us what’s happening:

Your code so far

function nextInLine(arr, item) {
  // Your code here
  item = 1;
  var removedElement = testArr.shift();
  return removedElement;  // 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 (Windows NT 6.1; WOW64; rv:62.0) Gecko/20100101 Firefox/62.0.

Link to the challenge:

You’re putting 1 on the end of the array every time, regardless of what item actually is. So if I do nextInLine([1,2,3], 4) you’re going to ignore that 4 and use the number 1 instead, which is incorrect

1 Like

I’m not sure you are able to test it though, LOL :slight_smile:

Function clearly has to return array in order to test ability to pop as well, otherwise I can just return arr.shift() and it will always pass ))

This is true, but one of the tests is with an empty array, and this is the test that will fail.

1 Like

Smart and true, I didn’t think of it :slight_smile:

Also, you’re totally ignoring the “arr” parameter, using testArr instead. testArr is a separate variable defined outside of the function.

It might be helpful to review the basics about how functions work: