What I love about all of your comments… is how you haven’t shut down this conversation. I think I especially respect the experienced devs for not dismissing out of hand my (albeit very minor) issues with fCC.
This is a sample of what I wrote for this task, in order to help me understand it and I think this kind of thing might be helpful for some learners like myself (assuming the info is correct and I’m not saying I got everything 100%!) who are really just trying to orientate themselves in the new world of JavaScript.
My notes for Standing in Line
function nextInLine(arr, item) {
arr.push(item);
return item;
}
var testArr = [1,2,3,4,5];
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6));
console.log("After: " + JSON.stringify(testArr));
Looking above we can see that
There is a variable called testArr = [1,2,3,4,5];
(“Before: “ + JSON.stringify(testArr)); reads out the initial state of the variable onto console.log
A function has been declared and named nextInLine
The nextInLine function has parameters in parenthesis (arr, item)
The nextInLine function will take place
Non-specific parameters (arr, item) have been replaced by specific parameters (testArr, 6)
The function instructs the console to push the item parameter (6) on to the arr parameter (testArr). By this point the console.log returns
This is because the function is simply returning the item as it is after the first event, but we want to remove the 1 from the return…
function nextInLine(arr, item) {
arr.push(item);
return arr.shift();
}
var testArr = [1,2,3,4,5];
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6));
console.log("After: " + JSON.stringify(testArr));
Now the function has been altered slightly so that the arr parameter (testArr) has the 1 removed using the .shift() instruction.
Two main events take place in this function before returning the “After: “ + JSON.stringify(testArr));
When we call the function our console.log returns