Mysterious organism: printing [function:mutate]

Hello,
I’ve been making a start on the mysterious organism project and have hit a wall. When I try to test the function it prints mutate: [function:mutate]
I’ve copied the code below as well as what the console prints.
Any help would be much appreciated, I cant seem to see the error!! :slight_smile:

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 this.dna

}

const pAequorFactory = (num, arrayDnaBase) => {

return {

specimenNum: num,

dna: arrayDnaBase,

mutate() {

let randomBase = returnRandBase();

let randomIndex = Math.floor(Math.random() * 15);

//the while loop ensures that the random generation will repeat until it comes up with a unique iteration

while (this.dna[randomIndex] !== randomBase) {

this.dna[randomIndex] = returnRandBase();

}

return this.dna;
}
}
};

const pAequor = [ β€˜T’, β€˜C’, β€˜G’, β€˜T’, β€˜A’, β€˜T’, β€˜A’, β€˜C’, β€˜T’, β€˜C’, β€˜C’, β€˜C’, β€˜G’, β€˜C’, β€˜G’ ];

console.log(pAequorFactory(1,pAequor));

WHAT THE CONSOLE PRINTS
{ specimenNum: 1,
dna: [ β€˜T’, β€˜C’, β€˜G’, β€˜T’, β€˜A’, β€˜T’, β€˜A’, β€˜C’, β€˜T’, β€˜C’, β€˜C’, β€˜C’, β€˜G’, β€˜C’, β€˜G’ ],
mutate: [Function: mutate] }

Looks fine to me, what do you expect it to do?

console.log(pAequorFactory(1,pAequor)); will print the object that is created by the factory function. As .mutate() is a method of that object, the console truncates it show that there is a function there called β€˜mutate’, without printing the entire function.

If you are trying to create a pAequor and then mutate it, you would need to generate it with a factory function, and then call the .mutate() method.

1 Like

Hi,
Thanks for taking a look.
I wanted it to print the mutated string which should have 1 base swapped out for something random.
I’ll take the mutate method out of the object and have another look.
Thanks!

1 Like