Basic JavaScript - Stand in Line

Tell us what’s happening:
Describe your issue in detail here.

/* In the challenge tests on the very bottom left side of the website screen , the last test reads: After nextInLine (testArr, 10) , testArr [4] should be 10. Community! can you please help me understand or explain step by step how the nextInLine function is processing this function call when these values are passed as arguments into the function. Thanks for your help in advance. */

Your code so far

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

  // Only change code above this line

// Setup
let 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/605.1.15 (KHTML, like Gecko) Version/15.3 Safari/605.1.15

Challenge: Basic JavaScript - Stand in Line

Link to the challenge:

What do you think this line does?

I ask because I think you have a misunderstanding here that makes this one line wrong

Thanks for the reply but this line just removes and returns the first element in the testArr array and it works just fine. That’s not what I as asking but thanks again for the fast reply.

Its processing them the same way it was processing the other function calls. It just that its using a variable storing an array, rather then an array literal.

The testArr[4] part is just indexing into that array. And at index 4 there should be a 10, because you pushed a 10 and removed 1 with the function call.

I get the testArr {4] part. What I’m struggling with is how is it processing
the (testArr , 10) and testArr{4} simultaneously to get a return value of 10??
thanks for the reply.

It is not doing it simultaneously.
It is creating a variable that has the test array and then calling your function in a series of calls.

I’m assuming u mean
the: let testArr = [1, 2, 3, 4, 5] as the variable it’s creating that has the test array or did u mean the -arr variable in the function?

Yes I meant the test case has its own version of the array which it passes to your function.

thanks for the fast reply!

1 Like

Its the same idea with that line and the test case. shift is a function call, and that function call went fully resolve before the return executes.

For the test, nextInLine(testArr, 10) executes and then the value of testArr[4] is checked.

In JavaScript, separate tasks are done separately. There is no ‘simultaneously’

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