i am stuck hier is screenshot

You’re supposed to be pushing item into the array, but you’re pushing the number 10

1 Like

thnks DanCouper now my code is working

arr.push(item) not arr.push(10)
full code is hier
function nextInLine(arr, item) {
// Your code here
item= arr.shift();

return item; // Change this line


// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr,10)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));


is there any reason for which you are overwriting one of the function parameters?

this a aquestion i was asked to do ?
Write a function nextInLine which takes an array ( arr ) and a number ( item ) as arguments.

Add the number to the end of the array, then remove the first element of the array.

The nextInLine function should then return the element that was removed.
but read this link i thnik it will help you

and you are doing that correctly
but do you really need to overwrite the item variable which is one of the function parameters?

goed question let me remind you this .
Javascript array shift() is an inbuilt function that removes the first item from an array and returns that removed item. The shift() method changes the length of the array on which we are calling the
shift() back to your question
item= arr.shift();
i am assigning item to the value i removed from the arry

in the function nextInLine(arr, item) item is an argument but you can give any value when you calling fucntion

return item; u can use instead
return arr.shift();
for more details look the link below and this only what i know i am still student. if you have more info please share with us thnks

1 Like

let’s make it short…
never overwrite a function parameter if you don’t have really good reason for it

in this case you certainly don’t need it, and you could also avoid that assignment and directly return the value from shift (return arr.shift)

1 Like