Basic JavaScript - Stand in Line

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

function nextInLine(arr, item) {
  // Only change code below this line
  arr = [1, 2, 3, 4 , 5];
item = arr.push(6);
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/111.0.0.0 Safari/537.36 Edg/111.0.1661.54

Challenge: Basic JavaScript - Stand in Line

Link to the challenge:

Tell us what’s happening:
// running tests

nextInLine([2], 1)

should return

2
nextInLine([5,6,7,8,9], 1)

should return

5

After

nextInLine(testArr, 10)

,

testArr[4]

should be

10

// tests completed // console output Before: [1,2,3,4,5] 1 After: [1,2,3,4,5]

Your code so far

function nextInLine(arr, item) {
  // Only change code below this line
  arr = [1, 2, 3, 4 , 5];
item = arr.push(6);
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/111.0.0.0 Safari/537.36 Edg/111.0.1661.54

Challenge: Basic JavaScript - Stand in Line

Link to the challenge:

You have a few issues here

You don’t want to create your own array here.
You should use the arr parameter they already gave you instead.

you don’t want to hardcode 6 here.
You want to use the parameter they gave you instead.

You don’t want to assign the result of this push to item and overwrite that value.
Also the push method returns the new length of the array

I would suggest reseting the lesson.
Your answer only needs to be 2 lines of code.

Good new is that you have already identified that you need to use the push and shift methods to solve this.
But you need to remove all of the other extra stuff you created that I just mentioned that is causing you to fail the test.

hope that helps

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