Link to the Challenge project on codecademy
I am working on step four at the moment and am stuck, I am not sure if my code works as when I try to console.log or return it, it only says the callback function, I am probably missing some tiny thing or just being plain stupid, but any help would be greatly appreciated
Here are the results I’m getting:
{ specimenNum: 8,
dna: [Function: mockUpStrand],
mutate: [Function: mutate] }
[Function: mockUpStrand]
{ [Function: mockUpStrand] ‘10’: [Function: returnRandBase] }
I have no idea why it is saying 10, it should be saying one of the letters ‘A’ ‘T’ ‘C’ or ‘G’
Here is 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 strand of DNA containing 15 bases
const mockUpStrand = () => {
const newStrand = []
for (let i = 0; i < 15; i++) {
newStrand.push(returnRandBase())
}
return newStrand
}
// factory function - makes objects
const pAequorFactory = (num, basesArr) => {
object = {
specimenNum: num,
dna: basesArr,
mutate() {
randomNum = Math.floor(Math.random() * 15)
digitCheck = object.dna[randomNum]
object.dna[randomNum] = returnRandBase
console.log(returnRandBase)
if (object.dna[randomNum] === digitCheck) {
object.mutate()
} else {
return object.dna
}
}
}
return object
}
console.log(pAequorFactory(8, mockUpStrand))
console.log(object.dna)
object.mutate()
console.log(object.dna)
On this line:
console.log(pAequorFactory(8, mockUpStrand))
,
you want what the mockUpStrand
function returns to be one of the arguments, so the that should be a function call:
mockUpStrand
should be
mockUpStrand()
Similarly,
on the line:
object.dna[randomNum] = returnRandBase
You want the result of the function call, not the function itself, to be inseted into the .dna
array.
So
returnRandBase
should be
returnRandBase()