nextInline array stuck

Tell us what’s happening:

I don’t think to understand how to go about this. I am completely stuck here. I will really appreciate your help, so that i can proceed with my lesson.

Your code so far
function nextInLine(arr, item) {
// Your code here
var arr = [1,2,3,4,5];
arr.shift();

return item; // 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));


function nextInLine(arr, item) {
  // Your code here
 var arr = [1,2,3,4,5];

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

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

Regarding this, I’m confusing between these 2 different result but seem from the same process:

var arr = [1,2,3];
var removed = arr.shift();
console.log(removed); // the result is 1

but in the same thing if I don’t use the variable removed then it is:

var arr = [1,2,3];
arr.shift();
console.log(arr.shift()); // result is 2

so the thing I would understand here is the arr.shift() has removed the second element of the array.

thank you for any help.

Hi Tony…

I am relativly new to coding but as far as I understand console.log() is a function. That is why it “executes” the argument “arr.shift()” when entered directly between the parantheses.
Since “arr.shift()” allready has been executed one line before, which removed the “1” from the array the next in line is “2”.

as opposed to

when passing the variable “removed” as an argument, the console.log’s “execution-command” is to read the variable “removed”. without executing “arr.shift()” again.

note: don’t be confused by the word “execution-command” as I just made it up.