Mysterious Organisms Step 7 - How To Create and Save 30 Instances

Hello Everyone!

I’m finally on the last step, step 7, of Mysterious Organisms! I’m not sure how to create and save 30 instances of the willLikelySurvive arrays. As always, I’ll be so grateful for some guidance. Here’s a link to the project Link

And here’s my 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 = (specimenNum, dna) => {
    return {
      specimenNum : specimenNum,
      dna : dna,
      mutate() {
        let dnaM = this.dna[Math.floor(Math.random() * this.dna.length)];
        let randI = [Math.floor(Math.random() * 14)];
        this.dna.splice(randI, 1, dnaM);
        if (this.dna === mockUpStrand) {
          mutate()
        } else {
          this.dna;
        }      
        },
      compareDNA(specimen) {
        let zip = [];
        let array1 = this.dna;
        let array2 = specimen.dna;
        let matchCount = 0
        for (let i = 0; i < array1.length; i++) {
          zip.push([array1[i], array2[i]]);
          if (array1[i] === array2[i]) {
          matchCount++;
        }
        }
        let percent = (matchCount / 15) * 100;
        let p = percent.toFixed();
          console.log('Specimen ' + this.specimenNum + ' and specimen ' + specimen.specimenNum +  ' have ' + p + ' percent DNA in common.');
          },
      willLikelySurvive() {
        let arrayS = this.dna;
        let matches = 0;
          for (let j = 0; j < arrayS.length; j++){
            if (arrayS[j] === 'C' || arrayS[j] === 'G'){            matches++;
              } 
          }
            let value = ((matches / 15) * 100);
              if (value >= 60) {
              return true;
            }
              else {
              return false;
              }  
          }
            }
        }

const survivors = ( ) => {
  let survivorStrands = [ ];
  let org1 = (pAequorFactory(1, mockUpStrand()));
  org1.willLikelySurvive();
  if (returns true) //this isn't working, throwing an error {
    survivorStrands.push(org1);
  }
}












  
  
      
      
    














1 Like