Basic JavaScript - Stand in Line

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

Challenge: Basic JavaScript - Stand in Line

Link to the challenge:

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:

Return the variable.

1 Like

Javascript can be hard so it takes more time to learn and get used to than stuff like html and css. What have you tried to pass this challenge?

Here is a hint you will use the push method to add the number and the shift method to remove the first item

1 Like

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?

I’d be thankful for the help.

Cheers.

1 Like

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.

Thank you.