Basic JavaScript - Stand in Line

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

Your code so far
i don’t understand this part,please can someone expalin me?

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

// Setup
let testArr = [1, 2, 3, 4, 5];
function nextInline{}

// 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/117.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Stand in Line

Link to the challenge:

Which part don’t you understand?

Do you know what an array is?

Do you know what push does?

Do you know what shift does?

You need to be able to explain those three things before you can successfully complete this challenge.

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

Can you attempt to answer my questions?

an array is like list, i can be like sum=[1,2,3,4],push adds an item at the end of an array,and push removes from the from.

Explain this bit more. What does push shift remove? Where does it put the thing it removed?

i don’t really know,i gues it should be returned by a function.

When in doubt, Google it:

What does this page have to say about where shift puts the removed element?

this where i s stick

Did you read the website I linked?

What does it say about where the removed element goes?

Thank you a lot for the hint,now i undestand that i should store it in variable and return this variable.:facepunch::facepunch:

1 Like

thanks for the information

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