Challenge Project: Mysterious Organism Step 4 - console.log to check work

Hello. I cannot seem to do a console.log() on the mutate function to check my work. Can someone explain how to call this to check it? Here is my code - When I put that console.log in , nothing shows in output. Thanks for any assistance!

const pAequorFactory = (number, dnaStrand) => {
return {
specimenNum: number,
dna: dnaStrand,
mutate() {
let i = Math.floor(Math.random() * this.dna.length);
let original = this.dna[i];
dnaBases.splice(dnaBases.indexOf(original), 1);
let mutator = dnaBases[Math.floor(Math.random() * 3)];
return this.dna.splice(i, 1, mutator);
}
};
};
console.log(pAequorFactory.mutate());

I think you need to make a pAequor object, and test the mutate function on that.
You can replace the console.log( ) you have now, with:

let pAequor1 = pAequorFactory(1, ['A', 'T', 'A', 'G', 'C', 'T'] );
console.log(pAequor1.mutate());

Here, pAequor1 was the object created by the pAequorFactory function
and instead of the array argument above, you may want to use mockUpStrand() .

Also, to check that .mutate() changed the .dna ,
you may want to use console.log on a pAequor object’s .dna
before doing the .mutate() and again afterward.

Test of the code below … (it first prints out the thing in .dna that was replaced).

const dnaBases = ['A', 'C', 'G', 'T']; const pAequorFactory = (number, dnaStrand) => { return { specimenNum: number, dna: dnaStrand, mutate() { let i = Math.floor(Math.random() * this.dna.length); let original = this.dna[i]; dnaBases.splice(dnaBases.indexOf(original), 1); let mutator = dnaBases[Math.floor(Math.random() * 3)]; return this.dna.splice(i, 1, mutator); } }; }; let pAequor1 = pAequorFactory(1, ['A', 'T', 'A', 'G', 'C', 'T'] ); console.log(pAequor1.mutate()); console.log(pAequor1.dna);
1 Like

// check mutate
// first create some mutations

const mutation = pAequorFactory(1, mockUpStrand());
const mutation2 = pAequorFactory(2, mockUpStrand());

//now console.log them
console.log(mutation)
console.log(mutation2)

let me know if this helps

2 Likes

Thank you so much! I was stuck for quite some time trying to test this code.