Stand in Line. just like at walmart

I can’t get my head around this stuff. I don’t understand what is supposed to happen. where to put the numbers. Nothing.

Your code so far


function nextInLine(arr, item) {
  // Your code here
  arr.push(item);
  var remove = 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, 6)); // 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

You’re very close. The devil is in the details.

So the function passes an array, and an item to append to that array. When you append that item, you should remove the first item from that array (as you’ve done, to a variable you’ve named remove). Then, you should return the item that’s been removed from the array (which you try to do by return removed).

Only issue is, you have no variable named removed to return. Where did you assign that pesky arr.shift()? that is what you want to return.

1 Like