StandInLine challeng

function nextInLine(arr, item) {
// Your code here
var push = arr.push(item);
var shift = arr.shift(item);
return item; // Change this line
}
nextInLine(testArr,6);
// 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));

This is the code so far,can someone tell me whats happening

Can you please specify clearly what is the challenge, or better add a link to the challenge?
Can you please also format your code using backticks? You can use the </> button in the post editor

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/stand-in-line

Do you understand what is the requirement of the challenge?

We have to create an array which is like a queue ,removing an item from the front for which i used shift() and adding the last item using push()

Then I suggest you to check how push() and shift() work
And I remind you you need to return the element that was removed from the array

Here the pages on those methods in the documentation:

function nextInLine(arr, item) {
// Your code here
 arr.push(item);
  return arr.shift(); 
}

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 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.

markdown_Forums

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.

1 Like

This is a learning site so we try to discourage people from blurting out the answers. Plus, it’s a bit of a slap in the face to the people that were trying to patiently guide the camper to the answer. If you feel you must present the answers, please be sure to blur them so people have the option of not seeing the answer.

Thanks for all the replies you took time to give,I passed the challenge without the hint though.

1 Like