Basic JavaScript: Stand in Line_05

Basic JavaScript: Stand in Line_05
0

#1

Tell us what’s happening:
I’m failing the lesson test, and I don’t know why.

Your code so far
function nextInLine(arr, item) {
arr.push(item); // Your code here

return arr.unshift(arr[0]); // Change this line (already changed)
}

// 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));


function nextInLine(arr, item) {
  arr.push(item);// Your code here
  
  return arr.unshift(arr[0]);  // 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: Google Chrome: Version 67.0.3396.99 (Official Build) (64-bit) , Windows 10 Pro.

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


#2

so you are pushing the item correctly to the end of the queue but you need to remove the first thing in the array

unshift adds to the array
Can you think of a way to remove something from the beginning of the array (you’re kind of close…)?


#3

Stupid mistake. I’ve been coding too long today. Thanks! (use shift not unshift method)