Can't understand the question - JS

Here is my updated code:

function nextInLine(arr, item) {
  // Only change code below this line
  arr.push(item);
  testArr.shift();
  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));

Still there is 2 fails left.

nextInLine([2], 1) should return 2

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

2 Likes

You are still using testArr. Only use the parameters in the function (arr, item).
Also, this is currently empty.

We are removing an element from the beginning right? Try to incorporate one of those parameters into your answer.

Also, when you fix this line you can place the return statement here.

I don’t understand

arr.push(item);
arr.shift(arr);  
return item;

sorry for ask you many things.

So we are not removing an array but rather an item right?

Yes.

What’s wrong with me code

You wrote this

Which this part translate to I want to remove an array.

Do you see it now?

Yes. i see it now.

The fails say

nextInLine([], 1) should return 1

nextInLine([2], 1) should return 2

1 Like

Can I see your code?

function nextInLine(arr, item) {
  // Only change code below this line
  arr.push(item);
  arr.shift(arr);
  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));

Actually, I am sorry this part was correct

I’m a dummy shift already removes the first element from the beginning of an array. Sorry about that. Must be tired. :smiley:

The test still passes if you pass through a parameter. So I guess it is very forgiving.

But you do need to return the second line

1 Like

All make Mistake

In which line?

How?

I am talk about this line.

You had it right with just arr.shift()
You just have to change the return statement. Right now you are returning item when you need to return the element that was removed.

Hint:
arr.shift()
Your answer only needs to be two lines of code not three

Were you able to pass the challenge?

It is Night 8:42 PM Here
So I will try it tomorrow.

Well you are super close. You just have to add the return statement in front of here.

arr.shift()

and delete this line

return item

1 Like

Hey @jwilkins.oboe!
OMG!

I passed the test.

I did as you said in

return arr.shift();

Thanks all for your Guides

4 Likes

Congratulations
But the problem is to understand what is happening instead of only pass the exercise. If you have a function more complicated you need to know what shift() is doing. In my opinion, for practice and understanding what is happening i would return a stored variable. Even if many times you can use less code, for readability or reusability you need to do a little more.

2 Likes

Hey @smc!
Thanks for your advice.

But I already understood the problem