Basic Algorithm Scripting: Mutations => problem

Hello I have a problem on this challenge… So I’m here to ask for help, here you can see my code :

function mutation(arr) {
for(let i=0; i<arr[0].length;i++) {
for(let j=0; j<arr[1].length;j++) {
if (arr[i]!==arr[j]) {
return false;
} else {
return true;
mutation([“hello”, “hey”]);

This is works for all the cases where the result should be true but not where it should be false… I read some solutions about it but I don’t understand what is wrong with my code if someone can help me please… Thank you :slight_smile:

First of all arr[0] and arr[1] are the two words, so your code will not do what you want and arr[0] !== arr[0] is always false as you are writing "hello" !== "hello", as that your function will always return true

Then, it seems that what you want to do is checking the letters one by one, but that method will never work

If you confront HELLO and LEO it should return true
But with your code

"H" === "L" // the function return false because you are checking only the first letters

I will suggest the method includes()

I suggest looking at your code with this

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


1 Like

Thank you I will try with that method !