Not tracking 100% w/ the lesson "Stand in Line"

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
  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.

Link to the challenge:

(unable to post links yet…)

Hi @Isaac-Tait, welcome to the community!

Your solution is correct, were you able to pass the challenge?

I’m happy to help with some of your questions:

  1. You can name the parameters whatever you want. You can change item to num if you wish, it doesn’t matter.
  2. arr.push(item) tells the JavaScript engine you want to add item to the end of the array. You will always need an argument for .push(). Without an argument inside the parentheses, JavaScript won’t know what you want to add to the array.
  3. arr.shift() is not removing item in particular, you are simply removing the first item of the array, no matter what it is. .shift() does not accept arguments.

I recommend you read the documentation for .shift() and .push() to fully understand.
.push() -
.shift() -

Happy coding!

1 Like

Thank you @austinlords for your insight and suggestions. I was able to pass the challenge but only by taking the hints route.