Help for stand in line javascript

Write a function nextInLine which takes an array ( arr ) and a number ( item ) as arguments.

Add the number to the end of the array, then remove the first element of the array.

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

Here’s the code:

function nextInLine(arr, num) {

  // Only change code below this line

  return item;

  // Only change code above this line

}

// Setup

const 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));

Hi @redeemerkyler, you should see in your console output an error like:

Before: [1,2,3,4,5]
ReferenceError: item is not defined

Which is generated from your function.
You have defined a function function nextInLine(arr, num) that takes two arguments: one called arr the other num.

But then in your function body you declare

return item;

Which is not defined anywhere so it’s throwing the error.
Why don’t you walk us with your logic and explain what where you try to attempt?

Also you might want to have a look on how to format your post to make it more readable:

ok I see. I haven’t done anything to the script this is how the challenge was given to me on freecodecamp.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.