Tell us what’s happening:
I’ve read the forums on this lesson, watched the video, implemented the sample solution (which I understand), and I am “passing” on this lesson, but I am not certain how. Specifically, I do not understand how I am meeting the criteria for conditions 3-5 without the numbers required being returned or implemented in any way. I didn’t want to move on until I understood how I was meeting the criteria.
Thanks.
**Your code so far**
function nextInLine(arr, item) {
// Only change code below this line
arr.push(item);
var removed = arr.shift();
return removed;
// Only change code above this line
}
// console.log(nextInLine);
// Setup
var 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/90.0.4430.212 Safari/537.36
arr.push(item);
this is assigning the parameter “arr” the subsequent value of “item” after it is pushed. In the case of the assigned array from “testArr”, the result would be [1,2,3,4,5,6] since we are adding a value of 6 in the second console.log line.
var removed = arr.shift();
this assigns the variable “removed” the value of “arr” after it is shifted. Since no value is being provided, it will return [2,3,4,5,6]
Now where I’m getting stuck is how to resolve the interactions with the new parameters. Namely, is the value of “item” simply replaced due to it being an integer, and the value of “arr” being appended due to it being in brackets (treated as an array)? Are both values replaced?
Ok, thank you. I think the root cause of my problem was reading the required checks as things I had to implement in the code, rather than checks being run in the background to see if my code was correct.
That being said, I’ll get back to:
function nextInLine([2], 1) {
rather - console.log(nextInLine([2], 1));
This should return 2, because:
arr.push(item); results in “arr” becoming [2, 1]
subsequently:
var removed = arr.shift();
return removed; results in the shifted value from “arr” of 2 being assigned to the variable “removed”
When I create additional entries of:
console.log(nextInLine([5,6,7,8,9], 1));
console.log(nextInLine(testArr, 10));
console.log(testArr[4]);