Help me in Basic JavaScript: Stand in Line

function nextInLine(arr, item) {

// Your code here


var removed = arr.shift(item);

return removed; // Change this line


// Test Setup

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

// Display Code

console.log("Before: " + JSON.stringify(testArr));

console.log(nextInLine(testArr, 6)); // Modify this line to test

console.log("After: " + JSON.stringify(testArr));`

it says that the value will be "before = [1,2,3,4,5] and after = [2,3,4,5,6] " why it is not [2,3,4,5,1]?
push takes the first item and add it to the back why they put 6 instead of 1 ?

push takes the argument you put in it, in this case item, the second parameter of the function, has value of 6
the function call is standInLine(testArr, 6)
6 is passed in item
and you push that as you write arr.push(item)

and for completeness, shift doesn’t need an argument, it doesn’t do anything with the argument you passed in

1 Like

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


1 Like

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

Thank you.