Basic JavaScript - Stand in Line

Tell us what’s happening:
Describe your issue in detail here.
Pls can someone help me out.
Your code so far

function nextInLine(arr, item) {
  // Only change code below this line
  testArr.pop(5)
  item = testArr.shift(5)
  
  return item;
  // 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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Stand in Line

Link to the challenge:

Here are the challenges I couldn’t solve

  • nextInLine([2], 1) should return 2

  • Waiting:nextInLine([5,6,7,8,9], 1) should return 5

  • Waiting:After nextInLine(testArr, 10), testArr[4] should be 10

What do you think this line does?

I think you should review this challenge on pop().

Pls I don’t understand the challenges.

You do not understand the challenge I linked? How did you pass it then? What do you not understand about the pop method?

Not your link :sweat_smile:, the challenges of my question. I already passed that one.

These are the remaining challenges.

The reason you are failing those tests/challenges is because you do not understand what the pop method does. Can you explain to me what you think testArr.pop(5) does?

I’ve removed it from the code.

You will have to post your latest code.

To post code into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

This is the new code

 testArr.pop()
  item = testArr.shift()
  testArr[4] = 10
  return item;

Please explain in your own words what you think this line of code does.

Thank you It isn’t suppose to be in the code. But it removes the last element of an array.

You posted the code with it in it, so I don’t know what to tell you.

Please post the entire function you are currently using to solve this challenge. Do not include code that is not really there.

Sorry, I’m a bit confused now.

Can you please post the full code in the challenge that you are using to solve this challenge? We can not help you if we can not see your latest full code.

testArr.push(5)
  item = testArr.shift()
  testArr.push(6)
  item = testArr.shift()
  testArr.push(7)
  item = testArr.shift()
  testArr.push(8)
  item = testArr.shift()
  testArr.push(9)
  item = testArr.shift()
  testArr[4] = 10
  return item;

The instructions are very specific.

You are supposed to add the 2nd argument (represented by item parameter) to the end of the first argument (represented by arr parameter). arr is an array, so Which array method adds a new element to an array?

The second thing you are supposed to do is remove the first element of arr and return it from the function. Which array method removes the first element of an array and returns the element removed?

If you are unable to answer these questions, then I strongly suggest you review the following challenges as it seems you do not understand how they work (based on the code you have written).

The pseudo-code algorithm is:

function nextInLine(arr, item) {
  // Only change code below this line
  
  // Add one line of code that adds `item` to the end of `arr`
  // Add one line of code that removes the first element of `arr` and assigns the removed element to a new variable.
  // return the new variable;

  // Only change code above this line
}

Thank you very much :grin:.