Mysterious Organism Project

Link to Exercise: https://www.codecademy.com/practice/projects/mysterious-organism

// Returns a random DNA base
const returnRandBase = () => {
  const dnaBases = ['A', 'T', 'C', 'G']
  return dnaBases[Math.floor(Math.random() * 4)] 
}

// Returns a random single stand of DNA containing 15 bases
const mockUpStrand = () => {
  const newStrand = []
  for (let i = 0; i < 15; i++) {
    newStrand.push(returnRandBase())
  }
  return newStrand
}

const pAequorFactory = (number, array15) => {
 let specimenNum = number;
 let dna = mockUpStrand();
  return {specimenNum, 
          dna, 
          mutate(){
          let random = this.dna;
     let i = Math.floor(Math.random()*15);
            let base = random[i]
            if (base === 'A'){
               return (random[i] = 'T', console.log(random));
              
           } else if(base === 'T'){
                     return (random[i] = 'A', console.log(random));
                     } else if (base === 'C') {
                   return (random[i] = 'G', console.log(random));
           } else {return (random[i] = 'C', console.log(random));}          
          }
         
         };
}


let test = pAequorFactory(1, mockUpStrand());
console.log(test);
test.mutate();

image

The above is my output… Why does my code randomly say mutate: [Function:mutate]}

Hello, @bhb23955.

The mutate() function is part of the test object you created with your pAequorFactory() function. When you console.log(test) it prints the object as you’ve seen in your output. If you only want to see a specific property of the object you can access them individually: console.log(test.dna) for example will only log the dna property’s value to the console.

For future posts, please review How do I format code in my posts?
Following the guidelines in that topic will make your code appear as it does now after I formatted it.
Happy coding!

1 Like

Okay that makes sense!

Thanks

1 Like