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

The nextInLine function takes two arguments (an array which should be testArr and an item to add to the end of the array passed to the function). You changed the call to nextInLine such that the first argument is testArr[4] which is 5 (the fifth element of testArr). This is a problem, because since arr is now a number (5), the code errors out with arr.push is not function. Only change the 2nd argument value for testing purposes.

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