I am confused by this lesson. As I walk through the code I understand it as follows:
Line 1: The function is named “nextInLine”. nextInLine is defined by an arr and an item…
Question 1: Could nextInLine be defined with arr and num instead of arr and item?
Line 4: I am taking arr and pushing its character to the end of the function “nextInLine”.
Question 2: Why do I need item defined inside of the ()?
Line 5: I now create a variable named “removed” that takes the first item within the array and saves it to the variable so that I can return it (aka print it to the console) in Line 6.
Question 3: Why is item not defined within the () this time around?
My code so far
function nextInLine(arr, item) {
// Your code here
arr.push(item)
var removed = arr.shift();
return removed;; // Change this line
}
// Test Setup
var testArr = [100,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr)); // Before: [100,2,3,4,5]
console.log(nextInLine(testArr, 99)); // 100
console.log("After: " + JSON.stringify(testArr)); //After: [2,3,4,5,99]
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36
.