Mysterious Organism Step 4

Hi there,

I’m having so trouble with the step 4 of the challenge. I created a do…while loop to mutate the dna, but it only works about 95% of the time - (the other 5% of the time it returns an identical copy of the oringal dna).
I also tried writing a for loop with a breaking condition and a while loop, but the same error keeps happening…Can somebody please help me with this?

1 Like

I think the problem is that you don’t create a variable, assign returnRandBase to it, then use the variable after.
Instead you call returnRandBase, and every time it gets called, a new value gets used.
What it means is that while loop checks for example A, while actually T gets mutated.

I hope this helps :grinning:

1 Like

Hi, thank you for your answer.

I understand what you are saying, but I’ve tried that and it does not work all. I tried creating a variable both with local and global scope and it turns out that when I try to log the method to the console, nothing happens :confused:

1 Like

Finally managed to do it :raised_hands:

You put me in the right direction by calling my attention to the fact that everytime I called returnRandBase(),a different base would come up, so I did this instead:

mutate () {

  let newDna = this.dna;

  const randomIndex = Math.floor(Math.random()*this.dna.length);

  let newBase = newDna[randomIndex];


    newBase = returnRandBase();

  } while(newBase === this.dna[randomIndex]);

  newDna.splice(randomIndex, 1, newBase);

  return newDna;


Thank you so much!

1 Like