Not recognizing my returns?

Tell us what’s happening:
Hi guys,
From my output, I seem to fulfill all the conditions of the task but it looks like the site doesn’t recognize my code as correct. Maybe I’m wrong? I believe first off that the site sees my return as a string and not as a number but I don’t understand why.

I would appreciate any help I can get with this.

  **Your code so far**

function nextInLine(arr, item) {
// Only change code below this line
var removedElement = arr[0];
return removedElement;
// 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/89.0.4389.128 Safari/537.36.

Challenge: Stand in Line

Link to the challenge:

Hi @zemezewo ,

Store the number which is removed after the push statement. That way, the returned value will never be undefined.

Look at the test scenarios under the instructions. One of them says,
nextInLine([], 1) should return 1

Check your code for all those conditions

In a situation like

nextInLine([], 5) should return a number.

this gives undefined instead of a number

Thanks, I tried storing the .shift() within a variable and then returning that variable and it works :+1:

Why does it though? I know the correct code now but I don’t quite understand why mine gave undefined. Sorry if I’m a bit slow with this.

in that case arr is an empty array, so arr[0] is undefined

1 Like

Ooh that’s what the [ ] meant, I thought it just meant any default array. Thanks for helping me understand :+1:

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