Hello there,
I am currently dealing with the Mysterious Organism project and I am facing a problem calling the .mutate() method of an object I made, inside the function pAequorFactory. More precisely, every time I call the function pAequorFactory I get on the debug console this : {specimenNum: 2, dna: Array(15), mutate: ƒ}.
I cannot understand why it’s not giving me the mutated array at mutate on the debug console, but it gives the letter f. If I change my code and replace ‘return object’ at pAequorFactory with ‘return object.mutate()’ I get the right result.
I guess I don’t understand something when it comes to calling an object that is inside a function and contains a method in it. Any insight please?
Thank you for your time, 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 stand of DNA containing 15 bases
const mockUpStrand = () => {
const newStrand = []
for (let i = 0; i < 15; i++) {
newStrand.push(returnRandBase())
}
return newStrand
}
const pAequorFactory = (number, arrayFunc) =>
{
const object =
{
specimenNum: number,
dna: arrayFunc,
mutate()
{
let b = returnRandBase();
const dnaArray = this.dna;
const randomBase = dnaArray[Math.floor(Math.random()*dnaArray.length)];
for (let i = 0; i < dnaArray.length; i++)
{
if (dnaArray[i] === randomBase )
{
while (b === randomBase)
{
b = returnRandBase()
};
dnaArray.splice(i,1,b);
}
}
return dnaArray;
}
};
return object;
};
console.log(pAequorFactory(2,mockUpStrand()));
Here is also the link of the project : https://www.codecademy.com/paths/full-stack-engineer-career-path-21/tracks/fscp-javascript-syntax-part-ii/modules/fecp-challenge-project-mysterious-organism/projects/mysterious-organism#page-skip-to-content-target