Tell us what’s happening:
Describe your issue in detail here.
I am experiencing a frustration on this JavaScript journey. It’s been over 2 weeks and I still don’t understand most of it. Am I being hard on myself for not grasping what I learn each day? Cos I can’t even do this one activity, the Stand in Line activity, I watched he video and I realise that I’m lost.
Your code so far
function nextInLine(arr, item) {
// Only change code below this line
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/116.0.0.0 Safari/537.36
Your first task is adding the item at the end of the array. Use the push() method on the given array (here you use the function’s argument arr which represents the given ‘testArr’):
Then, declare a new variable (e.g. const newArr):
Use a shift() method on the same array (function’s argument arr) to remove the first element of the array, and assign that value to the variable:
Hi! I got lost in the part where ‘arr’ represents testArr. I’ve manage to get the results asked, but couldn’t pass to the next level without changing the
testArr.push(6);
return testArr.shift();
to
arr.push(item);
return arr.shift();
inside the function.
I can’t seem to understand why ‘item’ would add a 6, and if we want the ‘testArray’ to change how is it possible to use only ‘arr’ and still get the same results.
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36
I’m sure I’m missing some important details, can you please help?
If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.
The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.