Tell us what’s happening:
Describe your issue in detail here.
Maybe I don’t understand the instructions. However, I tried to add the number 6 to the array then I tried to delete its first item. Now, I don’t understand the results of the test and don’t understand what is required. Your code so far
function nextInLine(arr, item) {
// Only change code below this line
testArr = arr.push(6);
arr = arr.shift();
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.46
Thank you. I am thinking how to apply what you say, but it is mainly required to add the (item) to the array then to delete its first entry. This is why I used (.push) and (.shift). I don’t really know how to use both arguments along with that. Was that wrong itself?
I expect an answer please. Was it right or wrong that I used .push and .shift? Should I instead add and remove manually what is to be added or removed? I am confused about reusing the function within the function itself.
Tell us what’s happening:
Describe your issue in detail here.
From what is written in the console the returned element should be 6. As the element (item) should be returned, it should be 6. The conflict comes when the removed element is the first element in the array. If arr is redefined to start with 6 it ends with 10, but to add item at the end of the array item should then be 11. This is how I understand it. Can I repeat 6 at the end of the array rather than 11?May I know what is wrong in my understanding? Thank you. Your code so far
function nextInLine(arr, item) {
// Only change code below this line
return item;
answer = nextInLine(testArr.push(6), item);
answer = nextInLine(testArr.shift(), 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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.46
Tell us what’s happening:
Describe your issue in detail here.
From what is read in the console, the returned value is 6. This means that the array should start at 6, but in this case it ends at 10. I need to add the element (item), but coming at the end of the array it should be 11. This is the case unless what is added at the end of the array is not necessarily the number that follows the last. So, the conflict comes from the need to add (item) at the end of the array and the need to have the first element of the array equal to (item). This is how I understand it so far and i wish to know my mistake. Thank you. Your code so far
function nextInLine(arr, item) {
// Only change code below this line
arr = [6, 7, 8, 9, 10];
const removed = arr.shift();
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.46
The instruction: “Add the number to the end of the array…”
You should use the push method to add that item.
Also, you should return the number 1 from the array, which has been removed (you defined it already).
Your answer should be a total of two lines of code.
The first step is to add the number to the end of the array.
I would suggest going back to this part of your code because you were really close to the answer here
In that line there, you should not hardcode the number 6. Instead you need to use the function parameter they gave you. Remember that item is meant to represent a number.
Secondly, you should return the element that was removed.
You were on the right track here
I would suggest reading up on the shift method to understand what that method returns
That should help you understand why this line is wrong
Once you return the correct value, then you will pass the test.