Stand in Line arr.push is not a function

again I don’t see the problem.

Your code so far


function nextInLine(arr, item) {
 arr.push(item);
  var removed = arr.shift();
  return removed;  // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr[4])); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/stand-in-line

console.log(nextInLine(testArr[4])); 

This seems to have been changed

1 Like

yes i was using these to test it.

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

nextInLine([], 1) should return 1

nextInLine([2], 1) should return 2

nextInLine([5,6,7,8,9], 1) should return 5

After nextInLine(testArr, 10) , testArr[4] should be 10

ok how can i fix it so I can pass…

You can change it back to the original line.

console.log(nextInLine(testArr, 6)); // Modify this line to test

Or you can pass any value you want as the 2nd argument and make sure the first argument is testArr.

console.log(nextInLine(testArr, 'royalgreen50')); // Modify this line to test
1 Like