I got stock in basic javascript lesson on "stand a line"

I got the code correct through the help section but didn’t understand how these come about; 1. how the argument function should contain ‘(arr, item)’ instead of ‘(arrItem)’
2. how the shift code has only ‘arr.pusg(item)’ instead of ‘testArr.push(item)’
3. how the push code has ‘return arr.shift(item)’ instead of ‘return testArr.shift(item)’
4. how and where we get the console.log code from because i don’t understand how it was defined.

  **Your code so far**

function nextInLine(arr, item) {
// Only change code below this line
return arr.shift();
// 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/101.0.4951.41 Safari/537.36 Edg/101.0.1210.32

Challenge: Stand in Line

Link to the challenge:

  1. Because the function is called with two arguments. The array and the item.
nextInLine(testArr, 6)
  1. testArr is passed to the function as an argument when it is called.

  2. Same as 2

  3. It logs out testArr before and after the function has been called. Arrays are copied by reference (you might also see it called passed by reference). The function is mutating the array that was passed to it. That is, it is changing testArr even though it was passed into the function, that array is not a copy. The log is using JSON.stringify.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.