Mysterious Organism Task 4

Hi, i’m currently on Mysterious Organism task but i don’t understand it much.

  • Your team wants you to simulate P. aequor‘s high rate of mutation (change in its DNA).
    To simulate a mutation, in pAequorFactory()‘s returned object, add the method .mutate().
    .mutate() is responsible for randomly selecting a base in the object’s dna property and changing the current base to a different base. Then .mutate() will return the object’s dna.
    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.*

Can someone maybe break this down for me or rewrite it so i can understand it better?
I don’t want to cheat and copy some code. Pls help

Hi, there!

Are you still having problem with this task?

If so, this is how I can explain step four to you:

  1. You are to add the method mutate() to the object pAequorFactory().
  2. The mutate() method is to first, select a random value within the pAequorFactory()'s dna array
  3. Second, mutate() will call the helper method returnRandBase() to generate a new random base
  4. returnRandBase() will need to be called until its value does not equal the value of the random dna index
  5. When the value of returnRandBase() does not equal the value of the random dna index, it will replace the value of the random index
  6. Lastly, mutate() will return dna

Hopefully that makes sense, otherwise I will try to answer any questions you have as best as possible!

1 Like

Hi thank you, yes i’m still on it. I took a Day of break to easy my mind a little bit

1 Like

That is the correct thing to do when becoming frustrated. I hope you found the instructions helpful. Keep up the good work! :slight_smile:

1 Like

I literally just typed it down freehanded and it doesn’t show any signs of errors lol.

Your explanation was really good, now i have to find out if it’s actually working and how to console .log this hehe.

Big thank you <3

Edit:

After looking up the right syntax to console log all that, it’s now working. This is my code so far:

const returnRandBase = () => {
    const dnaBases = ['A', 'T', 'C', 'G']
    return dnaBases[Math.floor(Math.random() * 4)] 
  }
  
  // Returns a random single strand of DNA containing 15 bases
  const mockUpStrand = () => {
    const newStrand = []
    for (let i = 0; i < 15; i++) {
      newStrand.push(returnRandBase())
    }
    return newStrand
  }


const pAequorFactory = (num, arr) => {
  return {
    specimen: num,
    dna: arr,
    mutate() {
        let ranNum = Math.floor(Math.random() * this.dna.length)
          let newBase = returnRandBase()
          if (this.dna[ranNum] === newBase) {
            newBase = returnRandBase();
            }
            this.dna[ranNum] = newBase
            return this.dna
    }
  }
}

const test1 = pAequorFactory(1, mockUpStrand())
console.log(test1)

console.log(test1.dna);
console.log(test1.mutate());



/* output: 
{
  specimen: 1,
  dna: [
    'C', 'G', 'T', 'T',
    'G', 'G', 'G', 'C',
    'C', 'G', 'A', 'A',
    'C', 'A', 'A'
  ],
  mutate: [Function: mutate]
}
[
  'C', 'G', 'T', 'T',
  'G', 'G', 'G', 'C',
  'C', 'G', 'A', 'A',
  'C', 'A', 'A'
]
[
  'C', 'G', 'T', 'T',
  'G', 'G', 'G', 'C',
  'T', 'G', 'A', 'A',
  'C', 'A', 'A'
]
*/
1 Like

maybe for better understanding just chage “IF” to “WHILE”.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.