What am I doing wrong on this exercise?

Tell us what’s happening:

Your code so far

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

return item;

// Only change code above this line


// Setup
var 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 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36.

Challenge: Stand in Line

Link to the challenge:

what is that the challenge asks you to return from the function? what are you returning?

Basic JavaScript: Stand in Line

Above is the name of the challenge. I haven’t been this stumped throughout the challenges but this one, even with getting a hint and looking at everyones opinion I still am having a hard time.

do you understand what the challenge asks you to return?

I understand using .push and .shift that all makes sense but I don’t get what else it is trying to ask for.

The nextInLine function should then return the element that was removed.

what do you think this mean?

That’s where I am confused. I keep thinking of that as being in a sense a name of a variable. Perhaps reading in my book before doing this section would help.

stop for a moment to think about the code

if for example the input is [1,2,3], 4 can you explain in words what need to happen to the array and what is the output?

Add the number to the end of the array, then remove the first element of the array.

The nextInLine function should then return the element that was removed.

This may sound silly to ask but I’m new to this language. Throughout the challenges some of the examples…portions of each example look almost made up…however nextInLine to me does not.

I’m not asking you these questions just for, to help you at best possibility, I need to know how much you understand and not understand of the challenge

So you are having troubles interpreting the instructions, and would not be able to say what would happen to a specific input when given to the function you should write, right? you don’t know if the input is [1,2,3], 4, what is the output

Where I keep getting confused is when it’s asking for a return. Perhaps if I got some sleep I could focus a bit more.

Whats most confusing in the challenge on the bottom left it mentions returning the value of 10 but somehow from what I put it checks that one off.

it asks you to return the element that was removed , then define a variable and assign it the value of the romoved item, so:
var removed_item = arr.shift();
return removed_item; //add it to what you wrote previously (except the return you wrote)
I pretty suck too, don’t know anything in basic algorithm scripting so it makes me feel beter to help someone else :wink:

1 Like

lesson is not asking you to return item (which is 6) ,look at bottom in middle console in which function nextInLine is given values to its parameters 'testArr ’ to arr and ‘6’ to item; (while going to this lesson i was also confused here: didnt knew that what values parameters of function are taking)

but instead asking you to return the element which was removed by arr.shift()

testArr[4] should be 10

that is not about the output of the function, it’s checking if you changed the array in the correct way

your function does that correctly, but you do not have the correct output