Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stand in line challenge - wrong validation #9355

Closed
Tzahile opened this issue Jun 24, 2016 · 3 comments
Closed

Stand in line challenge - wrong validation #9355

Tzahile opened this issue Jun 24, 2016 · 3 comments

Comments

@Tzahile
Copy link

Tzahile commented Jun 24, 2016

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

@heldersepu
Copy link
Contributor

You should be using the parameter in your function not testArr

@heldersepu
Copy link
Contributor

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
}

@Tzahile
Copy link
Author

Tzahile commented Jun 24, 2016

Got it, thanks.

@Tzahile Tzahile closed this as completed Jun 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants