Stand In Line javaScript Exercise ! Stuck!

function nextInLine(arr, item) {
// Your code here
arr.push(item);
var removed = arr.shift();
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));

@Owamamwen Hey the arr.shift() should be asigned to one of the parameters of the function. You already have arr using the correct method.

Its because of the wording in the exercise that people get stuck on this one. And because we’re noobs. I think the first thing it says is to write a method but the method is already there so its totally confusing from there on out.

4 Likes

i managed to compete this exercise myself, but only after reading a bunch of explanation in this thread… i think the exercise is poorly designed/thought out for noobies at this stage of javascript/programming knowledge.

2 Likes

Eh. This was a pretty difficult one. There is way too much there that isn’t explained. It assumes way too much. Really recommend updating.

1 Like

This one breaks if you set the arr.shift() to a variable and then return the variable instead of just returning arr.shift(), even though that obviously outputs the same thing.

Hello World!!!, I’ve been 2 days to make it, but i did it, the problem was that we must to make a variable with arr.shift and then return it. We must to print the number we are taking off, thats our target in this exercise. Here i show you how i did it. I hope it help you, long life to code and i love python :slightly_smiling_face:

Hello what we must to do there is just print the number we are taking off, thats all, it is easier than it’s looks like, here i left my code, i ve been 2 days solving it, hahahahah, but finilly i did it, here i left the code

function nextInLine(arr, item) {
// Your code here
arr.push(item);
var restado=arr.shift();
return restado;// Change this line

}

// Test Setup
var testArr = [5,6,7,8,9];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 10)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

thanks alot i finally pass this confusing challenge

this is working for mew

function nextInLine(arr, item) {
// Your code here

arr.push(item);
var firstItemDelete = arr.shift(arr);
return firstItemDelete; // 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));

All of your break downs down thru here were so helpful! I admit…I had to go thru each one before I started making sense of it for sure. The key thing for me on this one? Right to Left! I was looking at the wrong side!! THANKS AGAIN!!

1 Like

You saved me i had the same error was overseeing! Thank you!

i read your explaination here like 10 times or more lol… finally i was blown and understand, thanks for help much appreciated

1 Like

I understand so much more after all this! FCC challenges are great but sometimes its lacking clear explanations. Thank you!

1 Like

No problem at all. I’m so glad that my explanations are still helping people.

Sorry about the long long wait in answering. It’s been a while since I logged in here. Anyhow, as you have probably figured out by now, FCC is short for Free Code Camp. :slight_smile:

1 Like

LOL lordt I feel silly.

But appreciate your reply. Thank you!

This seems to work.

change the Parameters

of the function nextInLine (arr, item) to nextInline (testArr, item)

// Working Code

function nextInLine(testArr, item) {
  // Your code here
  testArr.push(item);
  return testArr.shift();  // 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));

muchas gracias / thank you so much

I was stuck on this one as well, but I did like an earlier suggestion that made more sense for me:

function nextInLine(arr, item) {
// Your code here
arr.push(item);
var removed = arr.shift();

return removed; // Change this line
}

By actually declaring a variable named “removed” and setting it equal to arr.shift(), I could see the connection and was able to make more sense of it. It might be more code that I have to write, and could obviously be shortened, but for now as a newbie, it makes sense to write my code this way.