Mysterious Organism Challenge Project (JavaScript)

Here’s my solution:

I noticed that on some other solutions posted here, for 6 - chance of survival, array contains at least 60% 'C' or 'G' bases.

Some solutions are if its 60% of ‘C’+‘G’ bases but my solution is exclusive, as in it’s either 60% 'C' base or 60% 'G' base, is that right or did I misunderstand the exercise?

Hello, this is my solution :wink:

Hello everyone, I have doubt on step 9 part b: * Use the .compareDNA() to find the two most related instances of pAequor.
How can we compare the two most related instances of pAequor out of the 30 survived pAequor.??

here is my code:

Looking at Codecademy solution for section 4, I don’t see how it ensures that the new DNA base is different from the one it is mutating? Could somebody explain please?

The task requires:

For example, if the randomly selected base is the 1st base and it is 'A' , the base must be changed to 'T' , 'C' , or 'G' . But it cannot be 'A' again.

But the code just seems to select a randon DNA base and replace it with an equally random base. I can’t see the part in the code that makes sure the new DNA base is different from the one it is mutating.


mutate() {
      const randIndex = Math.floor(Math.random() * this.dna.length);
      let newBase = returnRandBase();
      while (this.dna[randIndex] === newBase) {
        newBase = returnRandBase();
      this.dna[randIndex] = newBase;
      return this.dna;

The while loop is key here. While the randomly returned base is equal to the base at the random index, the code to assign a newBase is repeated. This isn’t the most efficient way to ensure a change. In theory, the random base returned could be the same many times in a row. It would be much more efficient to select a random base from an array that doesn’t include the base we are trying to mutate.

Here is a solution. I tackled the extra challenges as well.

Completed the project. Here is my code for it. Found it to be pretty fun and enjoyable to code.

Yeah that’s what i thought. So it looks like Codecademy’s solution doesn’t satisfy the requirements of the task?

I wouldn’t say that. It will continue to generate a new base until it gets one that isn’t the same as the one it’s trying to mutate. It works. It just isn’t the most efficient way to do it.

Ah, so if the random base it returns is the same as the current base it will try again?

Yes. While they are the same, it will try again.

Here is my version. This was a fun project.