I am having trouble with Stand in line

Hello everybody I am new free code camper and I have a problem with this subject.
I have been working on the problem for a few days now and I think I understand the problem, but after I tested the program I got no pass to the next subject.

Here is the code:
function nextInLine(arr, item) {
// Your code here
testArr.push(item);
var removedItem = testArr.shift();
return removedItem; // Change this line
}

// Test Setup
var testArr = [5,6,7,8,9];

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

Please, I need to know what am I doing wrong is there something I am missing?
Thank you in advance.

You are using a global testArr variable. Why? You need to use the parameter they give you (in this case the arr parameter).

function nextInLine(arr, item) {
// Your code here
arr.push(item);
var removedItem = arr.shift();
return removedItem; // Change this line
}

// Test Setup
var testArr = [5,6,7,8,9];

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

Thank you IsaacAbrahamson! That part I didn’t think of it. I was focusing in the Display area code more than the actual function, probably burned from not stepping back. Anyway, thank you very much for the fast responding.

this helped me too. Thanks! I didn’t realize that you can take manipulate one parameter by calling it as you did.

You should read the array.prototype docs on MDN. Some methods mutate the array (in other words, change the array itself like push), and others like join and slice return a new array, which you then have to assign to a value.

1 Like

ok great. thanks for pointing me to this!