JavaScript Stand in Line

JavaScript Stand in Line
0

#1

Tell us what’s happening:

I’m trying to figure out what I am missing in my code

Your code so far

function nextInLine(arr, item) {
  arr.push(item);// Your code here
  arr.shift(item);
  return item;// 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:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36.

Link to the challenge:


#2

The challenge asks you to do 3 things:

  1. Add the number to the end of the array - Complete
  2. Remove the first element of the array - Complete
  3. Return the first element of array - Not Complete

Your function is returning item, which is the number that was originally passed into the function. Read the documentation for shift and you will find it returns the value you need. You could assign this returned value to a new variable and return this new variable (instead of item) or you could just return the call to the function.