Different code, same results, marked wrong

Tell us what’s happening:
I put in code that yielded the exact same results as both the video and the requirements from what I saw. I’m in no saying it was the best way to do it, but it got the same results. So now I want to know what was different and why I didn’t get the right answer? I did it two different ways both yielded the same results, but they were both ruled wrong.

Your code so far

function nextInLine(arr, item) {
// Only change code below this line
 // testArr.push(item);
//  arr = testArr.shift();
// console.log(arr);
  //return arr;
// arr.push(item);
// return arr.shift(item);
item = testArr.shift();
// console.log(item);
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 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0.

Challenge: Stand in Line

Link to the challenge:

The problem is your function calls for an argument arr, but then modifies testArr instead. So when I call nextInLine([2], 1) it ignores the [2] array I WANT to modify and modifies the testArr instead. :slight_smile:

1 Like

OHHHHH!!! I GET IT!!! I was referring to testArr, because I was assuming that somebody would always pass testArr, but it’s very close ended and lacks modularity. Because if someone passes any other thing or variable, the program ceases to work properly. Thank you man it helps a lot!