Stand in Lin. how to complete this task any one please give me an idea

Tell us what’s happening:

Your code so far


function nextInLine(arr, item) {
  // Your code here
  var arr  = [1,2,3,4,5];
  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([2], 1)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36.

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

Two problems here.

var arr  = [1,2,3,4,5];

Why are you putting this in your function? The point is that arr should be passed into the function.

And…

arr.push[item];

You are using square brackets here instead of parentheses. You use square brackets to access individual cells of the array. But you want push a method (function) of the array.

When I make those changes, your code passes.

2 Likes