Basic JavaScript - Stand in Line

Tell us what’s happening:
Describe your issue in detail here.
unable to return 2 from nextInLine([2],1)
Since the function can return only one variable at a time and unable to create another function.
Your code so far

function nextInLine(testarr, item) {
  // Only change code below this line

  item = 10;
  const b= testarr.shift();
  const c=testarr.push(item);
  return c;
  // Only change code above this line
}
const arr=[2];
nextInLine(arr,1);


// 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:

Hi there! Welcome to the community.

Why are you changing the value of the item variable?

Take another look at which value you are returning. The problem wants you to return the value that you remove from the array.

hello and welcome to fcc forum :slight_smile:

  • is there a reason why used “item=10”?!
    lets refer to instructions

nextInLine function should then return the element that was removed.

  • which variable “b or c” has that value?!
  • simply return that value

hapy learning :slight_smile:

Actually I need to return multiple variable within single function *
nextInLine([], 5) should return a number.

*nextInLine(, 1)should return1`

*nextInLine([2], 1)should return2`

*nextInLine([5,6,7,8,9], 1)should return5`

:After nextInLine(testArr, 10), testArr[4] should be 10(This is the reason I put item =10

That is incorrect.
You don’t need to create any variables for this challenge.

Your answer should be two lines of code

The challenge doesn’t want you to create any variables and assign numbers to them.

The challenge wants you to do two things.

  1. add an element to the end of the array using the correct array method
  2. remove the first element in the array using the correct array method and return that removed element

Let’s break down what this test actual means because this is where you are misunderstanding.

After nextInLine(testArr, 10) , testArr[4] should be 10

Here is the array we are using for the tests

let testArr = [1, 2, 3, 4, 5];

Your first line for your solution should use the array method that adds a new item to the end of the array.
When you have done that correctly your new array should look like this

[ 1, 2, 3, 4, 5, 10 ]

Then you will need to remove the first element of the array and return the element that was removed…
When you have done that correctly, your array should look like this

[ 2, 3, 4, 5, 10 ]

I would suggest resetting your code.
Remember that your answer should only be two lines of code
You should not touch any of the parameters.
Leave this part alone

function nextInLine(arr, item) {

Hope that helps

I need to cpmplete multiple following tasks whether the shifted value is being returned or the pushed value. How I can return both?

  • nextInLine([], 5) should return a number.

  • Passed:nextInLine([], 1) should return 1

  • Failed:nextInLine([2], 1) should return 2

  • Passed:nextInLine([5,6,7,8,9], 1) should return 5

  • Passed:After nextInLine(testArr, 10), testArr[4] should be 10

You are not returning the value from the push method.
You will only be returning the value from the shift method

For this failed test here

Your first line of code will add the number to the end of the array

[2,1]

then your second line of code should remove the first number from the array and return that removed number. For this test case that first number is 2 should your code should return 2

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