Tell us what’s happening:
Not sure what I’m doing wrong here… I added the push and shift lines, but still getting errors
Your code so far
function nextInLine(arr, item) {
// Your code here
testArr.push(6);
return item;
testArr.shift;
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:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/stand-in-line
Remember when you return from a function, everything after it cannot be reached. You’ve got two return keywords.
Also, make sure you understand what you are returning. Are you supposed to return item or something else?
Hi,
I see a few things…
You seem to be clear that using push and shift will alter the array as needed.
As @zapcannon99 stated once your program hits a return statement the function ends so anything after a return will be ignored.
You are pushing a number 6 onto your array instead of whatever number is passed to your function (item). Your function would only work if the number just happened to be a 6.
You should refer to the array and number by their “local” names in the function - arr and item
// function takes two parameters,
// an array locally named arr
// and a number locally named item
function nextInLine(arr, item) {
//Put item onto end of arr
//take first element off of arr
return ? // return the element removed from arr
}
// Test Setup
var testArr = [1,2,3,4,5];
// passing an array and a number to function nextInLine
console.log(nextInLine(testArr, 6)); // output should be 1
console.log("After: " + JSON.stringify(testArr)); // [2,3,4,5,6]
I think you’re very close to a solution. Good luck