Not understanding a JS course of freecodecamp

Can somebody explain me the linked course in simple words. The name of the lesson is “Stand in Line”.

What part don’t you understand? Can you tell us what parts do make sense to you and what you’ve tried so far.

I understood that to add and remove element from array, we have to use push and shift function. And to the removed element should be returned by assigning it to a variable. Like var x = arr.shift() . But the thing in the last section i.e array should return … etc. That part is what I am not getting. And also the elements are said to be removed and added in the array but where are the value for the array?! Thanks in advance!

Hey Preeti,

this lesson deals with the concept of a Queue.

You can find a Queue in real life a lot, e.g. when you stand in line in a shop (that’s where the lesson has its name of).

Line: 1 => 2 => 3

1 is the first person in line who wants to get served in the shop.
2 entered the shop after 1, that’s why (s)he is the second person in line who will get served.
3 entered the shop after 2 and after 1, that’s why (s)he is the third person in line who will get served.

The lesson wants you to do:

  • Add the number to the end of the array: a new person goes to the end of the line to get served
Line: 1 => 2 => 3 => 4
  • then remove the first element of the array: the first person in line gets served and walks away
Line: 2 => 3 => 4
  • The nextInLine function should then return the element that was removed: which person got served?
Removed: 1
1 Like

That is telling you what your function should return. In other words, your function should end with:

return x; // if x is the variable that you saved the removed value in
1 Like

Got it! Very well explained ! THANKS!

Okay ! THANK YOU! :)))