Hello all! Here is a link to the project Mysterious Organisms Link.
The step I’m on is:
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.
I’m getting the following error:
TypeError: pAequorFactory.mutate is not a function
Any help would be very much appreciated!
// 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() {
// generates a random DNA base
var mutatedDnaBases = ['A', 'T', 'C', 'G']
return mutatedDnaBases[Math.floor(Math.random() * 4)]
//Compares the randomly selected base to the 1st base
if (mutatedDnaBases === returnRandBase) {
//runs the generation of a random DNA base again
mutatedDnaBases[Math.floor(Math.random() * 4)]
} else {
//if the mutated base is different from the return base it logs it to the console
console.log(mutatedDnaBases)
}
},
}
}
console.log(pAequorFactory.mutate())