Basic JavaScript - Stand in Line *Please Help*

I am confused with where the information comes from in this challenge:
This is what I have so far and added a screenshot, perhaps a lesson link to guide me or what I am missing, feel like its simple or something someone can guide me to the answer; just heads up DO NOT COME from a technical background, more business and art experience. Use lamens terms or articles/videos to understand solutions too :blush:

Your code so far

function nextInLine(arr, item) {
  // Only change code below this line
  arr.push(item);
  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/114.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Stand in Line

Link to the challenge:

This line removes something from the array but you donā€™t put that removed item anywhere, so it disappears instead of being returned from your function.

1 Like

Hmmm if I am getting it correctly remove that bit. I will try it out. I thought it just replaced the certain element instead of remove?

Itā€™s giving me the same thing, is there an article or video to understand this because its becoming a riddle and been on this problem for a couple of days and moved unto other parts of the chapters, this one still incomplete :disappointed_relieved:

You need to use ā€˜.shift()ā€™, but you arenā€™t using the item that is shifted out of the array

1 Like
  • as jeremy pointed out its this gives you something back, you need to make use of that in that function
  • if you need some reading to do on this ā€œarray methodā€ then i would say this article from mdn might be useful to you, happy reading :slight_smile: Array.prototype.shift() - JavaScript | MDN
2 Likes

by just looking at the answers. I think everyone is holding out giving you the answer. So that you can learn by yourself. Which is awesome. Or did you eventually get the answer ? :grinning:

@flowOver Oh I know that they are with holding the answer, very very common in this industry of programming.

As for the links, @JeremyLT & @bappyasif , thank you!! I will look them over and havenā€™t gone over yet; just kept moving until I got to it again. Will be looking it over tonight! Thank you for the article! :blush:

2 Likes

Itā€™s not that we are ā€œholding outā€ so much as we are trying not to take away from you the process of figuring it out. That ā€œfiguring it outā€ process is a really big part of programming.

3 Likes

oh no ! i know its no in bad faithā€¦ its actually all love :heart_eyes: !!! how are we going to learn if we are given all the answers. ?? :rofl:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.