Mysterious Organism Project

Hello all,

I’m doing the Mysterious Organism Project and I’m stuck at task n4.
When I run the code below it returns undefined… I’m not sure what I’m doing wrong and I’ve really tried to fix it on my own but with no success :frowning: , so I would really appreciate someone’s help.

The link is here: 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 = (num, dnaB) =>{
   const info = {
     specimenNum: num,
     dna: dnaB,
     mutate() {
    let base = this.dna;
    let mutated = [];
     for (i = 0; i < base.length; i++){
        if(base[i] === 'A'){
       mutated.push['T'];
        } else if ( base[i] === 'T'){
          mutated.push['A'];
        }else if ( base[i] === 'C'){
          mutated.push['G'];
     }else if ( base[i] === 'G'){
          mutated.push['C'];
     } 
     return this.mutated;
     }
      
  return info;
      }
   };
}
 
   
console.log(pAequorFactory(76, mockUpStrand()));



1 Like

A few curly brackets were misplaced, usually this causes an error, but in this case it didn’t. Also there was one extra curly bracket.
Try to focus on the indentation as it makes debugging a lot easier.
Also you should try putting out the opening and closing brackets (not just curly but square brackets) together then go back and use line break (or enter) in between the brackets (usually not in square brackets case as arrays don’t tend to need multiple lines)
Here’s the code:

// 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 = (num, dnaB) => {
    const info = {
    specimenNum: num,
    dna: dnaB,
    mutate() {
      let base = this.dna;
      let mutated = [];
      for (i = 0; i < base.length; i++) {
        if (base[i] === 'A'){
          mutated.push['T'];
        } else if ( base[i] === 'T'){
          mutated.push['A'];
        } else if ( base[i] === 'C'){
          mutated.push['G'];
        } else if ( base[i] === 'G'){
          mutated.push['C'];
        }
      } 
      return this.mutated;
    }
  }
  return info;
};
console.log(pAequorFactory(76, mockUpStrand()));

if indentation looks weird (for me its ok but i don’t know if it will look different for you) that’s because of tabs, sorry

1 Like

Hi lolfail,

Thank you very much for your help :slight_smile:

Eventually I’ve figured out my mistakes on my own as no one was replying LOL.

But at least it forced me to really dig deep and find a solution.

Thank you very much for your time and for your help anyway, i really appreciate it.

Have a great day!

Alla

1 Like