Basic JavaScript - Stand in Line

Why is my code not passing the test.

Your code so far

function nextInLine(arr, item) {
  // Only change code below this line
  return arr.shift();
  // 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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic JavaScript - Stand in Line

Link to the challenge:

I’m not sure that you understand what your code is supposed to be doing?
Your function should add item to the end of arr and then remove the first item from arr and return it as the return value for the function.
You are pushing the value 10 to your array for some reason.

You are told to simply put the number in the beginning , which is defined in the question . it didn’t say 10.

You are to remove the first element of the array. You have passed the assignment on how to address elements in arrays of specific positions, right?

Yes, that part is correct, as the challenge specifies. It’s the .push() which is incorrect.

The challenge is quite specific remove the first element of the array.

Yes, that’s what the shift method does. It removes and returns the first element of an array.

Exactly so the assignment is on two things, which he has tried to solve but he/she has a little challenge along the line and that is what i am breaking down

The item you are removing should be stored in a variable.
const removeFirstItem = arr.shift();
return removeFirstItem

That may be good practice but it is not why the challenge is failing. The return statement works as is.

1 Like

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