**What is arr and item in the function?**

What is arr and item in the function?
Why are we using arr and item as paramters in the function?
Isn’t the array called testArr?

  **Your code so far**

function nextInLine(arr, item) {
// Only change code below this line
arr.push(item);
return arr.shift();
// Only change code above this line


}

// 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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36

Challenge: Stand in Line

Link to the challenge:

Hey there, hope your day is going okay!

arr is just an arbitrary name for the array in the nextInLine method.

When console.log(nextInLine(testArray, 6)); is called, test array is passed into
function nextInLine(arr, item) and can be accessed by using arr.

You can pass in testArray directly, however the testing system does not.
It will call function nextInLine(arr, item) with a unique array each time and compare the return value to an expected string.

Hope this helps!

This is how functions work.

Say you have a function add that adds two numbers.

function add (x, y) {
  return x + y;
}

So that doesn’t mean “take the literal letters x and y and add them up”. That function doesn’t return xy every time you run it. That would not be a useful feature of functions (in maths or programming or anywhere that uses functions).

What it means is that when you use the function, you give it two numbers, and it returns the sum of those two numbers added together.

In the standInLine function, arr and item are just like x and y in add

Thank you! hope your day is good as well. I still don’t quite understand what the item part is refering to in the function. You say that arr is referring to var testArr = [1,2,3,4,5]. But what is item referring to.

item is the parameter used for the second argument.

// function definition
function nextInLine(arr, item) {
...code
}
// function invokation
nextInLine(testArr, 6);

The argument testArr is passed to the arr parameter.
The argument 6 is passed to the item parameter.

So imagine you are waiting in line.
You and 2 other people are in the line.
You are 3rd in line.

So the array to represent that would be [1,2,3].
Given the number 2 as the ITEM, who is next in line?

That is to say, who is next in line after number 2? 3.

Hope that makes a little more sense!

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