I really need to be explained to what I am missing. I am confused and can’t seem to figure out what exactly I am doing wrong and what to fix.
function nextInLine(arr, item) {
// Your code here
arr.push(item);
arr.shift();
return arr.shift(); // Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Hello I have modified my code and made some progress:
function nextInLine(arr, item) {
// Your code here
testArr.push(item);
testArr.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(item); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));```
But I am unsure of how to modify the line:
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(item); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));```
your problem is what youre returning. The last line in the assignment says The nextInLine function should then return the element that was removed. What youre returning is the item that you are adding to the end of the line. remember that the shift function not only removes the first value in the array but also stores it.
okay so now you are not returning anything you need to return the value that you removed. Also you need to use the same name as the argument passed into the function parameters.
So where you put testArr you need to be putting arr. Also after the return statement you need to put arr.shift();
or you could assign arr.shift() to a variable and then return that.
You were close the first time, the problem with that one was that when you ran arr.shift() it removed the first element in the array. Then when you called the function again in the return statement, it ran the function again and returned the next value in the function.