Implement the Mutations Algorithm - Implement the Mutations Algorithm

Tell us what’s happening:

Here is my code:

function mutation(array) {
haystack = array[0].toLowerCase();
needle = array[1].toLowerCase();
for (char in needle) {
if (!haystack.includes(needle[char])) {
return false;
}
}
return true;
}

none of the tests in the https://www.freecodecamp.org/learn/full-stack-developer/lab-mutations/implement-the-mutations-algorithm UI pass, but when i run them in VS code by adding console.log for each test they pass.

What am i doing wrong?

Your code so far

function mutation(array) {
  haystack = array[0].toLowerCase();
  needle = array[1].toLowerCase();
  for (char in needle) {
    if (!haystack.includes(needle[char])) {
      return false;
    }
  }
  return true;
}

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36

Challenge Information:

Implement the Mutations Algorithm - Implement the Mutations Algorithm

Welcome to the forum :wave:

When I copy your code into the editor and try to console.log the result I get this error

ReferenceError: assignment to undeclared variable haystack

Did you investigate this?

fCC editor runs in strict mode, which is less forgiving than your VSCode environment is.

Yes I got it to work by adding "let " to every variable, so the working code was

removed by mod

1 Like

Glad you got it, please do not add solution code to the forum.