nextInLine test fail

I understand the method. When I run the tests, I pass lines 1,2,&5 but can’t figure out lines 3 & 4. I’ve changed my array and I get the required results but still fail the test.

function nextInLine(arr, item) {
// Only change code below this line
var removed = testArr.shift();
return removed; 

// Only change code above this line


// Setup
var 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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36.

Challenge: Stand in Line

Link to the challenge:

hint: look at this bit of your code - testArr

1 Like

You’re really close! Just forgot to initialize testArr to be the arr given. Something like: let testArr = arr;

Needs to be done so the function knows what array it’s working with.

1 Like

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

your function needs to be reusable,
for that you need to use both function parameters, not a global variable like testArr

1 Like

Thanks to all for the help.