arr.push(item);
const removed = arr.shift();
return removed;
this is the code in the hint, but unfortunately i dont still understand. the array defined in the challenge is testArr. why arent they using it for the push and shift but using only arr which is one of the parameters and not an array. i’m kinda slow so dont be pissed if my question appears dumb.
**Your code so far**
function nextInLine(arr, item) {
// Only change code below this line
testArr.push(item);
testArr.shift(arr);
// Only change code above this line
}
// Setup
const 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/104.0.0.0 Safari/537.36
The defined array only matters if the function is called and that array is passed in as a function argument. We don’t want to write a copy of this function for every single possible array we could want to use.
Maybe it would help to try to understand the concept of a function first.
Let’s pretend for a second that you are in a line outside of a store. The store has black windows and doors, so you cannot see inside. You are first in-line at the door but it is not your turn yet. Perhaps in this story, you cannot enter the store until a person leaves (there’s a maximum number of people allowed inside due to COVID-19 rules).
so - while you are outside, you are not “seen” by the store yet right? (black windows)
But as soon as someone comes out and you go in, now they see you and greet you.
Great.
A function is the same way as a blacked-out store.
It can only see what is given to it (on the inside of it).
So the function nextInLine for eg is not aware of anything going on below the last } brace (that matches the starting { brace in the definition ).
It can only see 2 things. arr and item.
So it therefore can only do interesting things with arr and item.
(well having said all that, there is also an idea of a global variable but I’m not sure if you learned this yet, but either way, hopefully you understood the idea of the function and its “scope”)
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.