Freecodecamp: Stand in line challenge - wrong validation

Created on 24 Jun 2016  ·  3Comments  ·  Source: freeCodeCamp/freeCodeCamp

Challenge Name: Stand in Line

https://www.freecodecamp.com/challenges/stand-in-line

Issue Description

When using push and shift function, the validation "nextInLine([5,6,7,8,9], 1) should return 5" shows I'm wrong.
However, when inserting manually the array '[5,6,7,8,9]' to testArr, and the argument '1' when calling the function, it returns '5'.

Browser Information

  • Browser Name, Version: Chrome, 51.0.2704.84 (64-bit)
  • Operating System: Ubuntu 14.04
  • Mobile, Desktop, or Tablet: desktop

Code

function nextInLine(arr, item) {
  testArr.push(item);
  item = testArr.shift();
  return item;  // Change this line
}
var testArr = [5,6,7,8,9];

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

Screenshot

screenshot114

Most helpful comment

Your code:

function nextInLine(arr, item) {
  testArr.push(item);
  item = testArr.shift();
  return item;  // Change this line
}

Correct code:

function nextInLine(arr, item) {
  arr.push(item);
  return arr.shift();  // Change this line
}

All 3 comments

You should be using the parameter in your function not testArr

Your code:

function nextInLine(arr, item) {
  testArr.push(item);
  item = testArr.shift();
  return item;  // Change this line
}

Correct code:

function nextInLine(arr, item) {
  arr.push(item);
  return arr.shift();  // Change this line
}

Got it, thanks.

Was this page helpful?
0 / 5 - 0 ratings