Tell us what’s happening:
When use this ask it to return item, it helps me pass half of this section, when I replace item with firstElemRemoved for return, it passes me on the other half. How can I make it return the firstElemRemoved and item and pass all of it altogether?
Your code so far
function nextInLine(arr, item) {
// Only change code below this line
let firstElemRemoved = arr.shift(0);
console.log(firstElemRemoved);
let nextElem = arr.push(item);
console.log(nextElem);
return item;
// Only change code above this line
}
// Setup
let 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));
Your browser information:
User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14816.131.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
So the ‘item’ is the next number to be pushed to the end of the array. I’ve worked out how to do this with this code:
let firstElemRemoved = arr.shift(0);
console.log(firstElemRemoved);
let nextElem = arr.push(item);
console.log(nextElem);
return item;
but then the instructions want me to also do the following:
nextInLine([2], 1) should return 2 nextInLine([5,6,7,8,9], 1) should return 5
I’ve replaced ‘return item’ with ‘return firstElemRemoved’ which it accepts but then it doesn’t calculate the item removed as I’ve asked it to return the number removed too. Is there a way to do both? Or am I missing a line of code which combines both?
I’ve changed the order to add the number to the end and then remove the first element. My understanding of the instruction is to use the number ‘item’ to add it to the end of the array, is that not correct? The ‘return item’ was already added to the task, I didn’t add it.