Mysterious Organism Project Issue

compareDNA(pAequor){

var count = 0

var dna = this.dna

for(let i=0; i < pAequor.length; i++){

  for(let j=0; j < dna.length; j++){

    if(pAequor[i] === dna[j]){count+=1}

  }

}

return count

console.log(count)

var amount = ((count / pAequor.length) * 100).toFixed()



return 'specimen #1 and specimen #2 have '+ amount +' DNA in common'

},

}

}
Count keeps returning 0?

Hi @jacobmarkowski1
Welcome to the forum!

it is not possible to tell why count stays 0 as long as we don’t know the argument you pass to the method. It is necessary that you provide more of your code.
Please make sure that it is properly formatted:
https://discuss.codecademy.com/t/how-to-format-code-in-posts/51139

This code is below a return statement. That means that it is not executed.

Also, please provide a link to the exercise.

Please format the code. I provided a link with a guide.

// 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 = (n, array) =>{
  return {
  specimenNum: n,
  dna: array,
  mutate(){
   var random = returnRandBase()
    //console.log(returnRandBase)
   
    if(random === array[0]){ return returnRandBase()}
    return returnRandBase()
  },
  compareDNA(pAequor){
    var count = 0
    var dna = this.dna
    console.log(array)
    for(let i=0; i < pAequor.length; i++){
      for(let j=0; j < dna.length; j++){
        if(pAequor[i] === dna[j]){count += 1}
  }
}   
    return count
    //console.log(count)
    var amount = ((count / pAequor.length) * 100).toFixed()
    return 'specimen #1 and specimen #2 have '+ amount +' DNA in common'
  },
  }
}

//console.log(pAequorFactory(1, mockUpStrand()))
//console.log(pAequorFactory(1, mockUpStrand).mutate())
console.log(pAequorFactory(1, mockUpStrand()).compareDNA(mockUpStrand))

You should pass mockUpStrand to the method compareDNA as a value, not as a function. That means you have to invoke compareDNA as you did in the factory.

1 Like

Ah, I see thank you!