Tell us what’s happening:
After spending hours on this, I ended up looking at the solution code and don’t understand how it works.
First, how does the function know which string we are referring to? Sure, we declared testArr, but at no point in the function do we specify it.
Second, how is the ‘item’ parameter specified to 6? I don’t see where that value is specified. I spent a ton of time trying to write a line that called the function and passed arguments into the parameters, which it turns out was causing me an error.
I hate admitting defeat by looking at the solution, but now I’m even more confused.
Your code so far
function nextInLine(arr, item) {
// Your code here
arr.push(item);
return arr.shift(); // 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 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0
.
Link to the challenge:
https://www.freecodecamp.org/challenges/stand-in-line