Stand in Line challange

I am unable to understand this problem well enough. hence not able to find a workable solution either.
Please help.

Here is the function I wrote:

function nextInLine(arr, item) {
  // Your code here
  return arr[0];
  arr.push(item);  // Change this line

Can you please edit your topic title to reflect what you need help with instead of just posting the challenge url?

Hint #1: to part of your problem. The order in which you do things matters. When a return statement is executed, any value specified is returned and the function exits immediately, so no other code will run.

All right!
Here is what I made it now:

function nextInLine(arr, item) {
  var toBeRet=arr[0];
  return toBeRet;  /

This problem says β€œthe nextInLine function should then return the element that was removed.”
But after running tests, error asks to return the values which were added:

nextInLine([], 5) should return a number.
nextInLine([], 1) should return 1

The problem with your function is that in the test case of nextInLine([],5) there are no elements in the array passed in, so arr[0] is undefined. Read the instructions carefully. You are not following the order of operations it wants. You need to flip two of the lines.

1 Like

Thanks for guiding through it. :smiley: