Stand in line challange issue

How is var testArr linked to the function nextInLine ?


function nextInLine(arr, item) {
// Only change code below this line

return item;
// 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));

Challenge: Stand in Line

Link to the challenge:

Hi @hibathulla_k !

Welcome to the forum!

The testArr is being used in this function call right here

It’s not really linked to the function but more so used in that function call if that makes sense.

You can use any array in that function call.

It is just that FCC chose that one.

Hope that helps!

1 Like

Thanks @jwilkins.oboe ,

How is the number 6 getting added to the array ‘testArr’ when we ad the code arr.push(item) ?

If you look at the function call here

nextInLine(testArr, 6)

The second argument is 6.

This line of code here

  arr.push(item)

is really saying this

  arr.push(6)

You are telling the computer to add 6 at the end of the array.

1 Like

Thank you soo much @jwilkins.oboe for your help. It really helped me to clear my confusion and understand the challenge better.

1 Like

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