Tell us what’s happening:
I’ve searched the forums and used the “Get Help” button, which I then watched the video and visited “Get a Hint”. However, the code below still fails.
Error I am receiving:
Failed: nextInLine([2], 1) should return 2
Failed:nextInLine([5,6,7,8,9], 1) should return 5
Your code so far
function nextInLine(arr, item) {
// Only change code below this line
testArr.push(item);
return testArr.shift();
// Only change code above this line
}
// Setup
let testArr = [1, 2, 3, 4, 5];
// Display code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6));
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/115.0.0.0 Safari/537.36
Thank you. I figured it out. I assumed they wanted me to target that specific array of testArr. The headache. My code now passed.
However, I don’t quite understand the logic. Why/How are the parameters of the functions able to be entered into the { }? I thought parameters were just place holders until we gave those placeholders an action to execute?
Typing out loud:
Assuming the provided “console.log(nextInLine(testArr, 6));” is defining the placeholder of arr and item. arr = testArr and item=6. — If this is true why is console.log defining placeholders? Shouldn’t that be done within { }
When we run .push(item) this action references the number 6 transforms the array into
[1, 2, 3, 4, 5, 6]
Then we .shift() which transforms array into [ 2, 3, 4, 5, 6]