Challenge Project: Mysterious Organism stuck at item N4

hi everyone, im looking for a better explanation of how to do this exercise, i found some questions and replays in the forum but i`d need to go one step back. This is the link to the exercies : https://www.codecademy.com/paths/front-end-engineer-career-path/tracks/fecp-22-javascript-syntax-part-ii/modules/wdcp-22-mysterious-organism/projects/mysterious-organism

i want to know hot to use de .mutate in this situation :
" 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."

THANKS

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
}

const pAequorFactory = (specimenNum, dna) => {
return {
specimenNum : specimenNum,
dna : dna,
}
}

//console.log(pAequorFactory(1, mockUpStrand(
)));

Not sure of which part of the instructions you need clarifications since you haven’t started writing the method yet, so I’ll try a general explanation:

const pAequorFactory = (specimenNum, dna) => {
return {
    dna : dna,
    mutate() {} // <-- in pAequorFactory()‘s returned object, add the method .mutate().
  }
}
dna: dna, // an array
mutate() {
  // returns an array with ONE item in the dna array changed
} 
const pAequor = pAequorFactory(1, mockUpStrand()); // an object
console.log(pAequor.dna) // logs for example [ 'A', 'T', 'T', 'T', 'G', 'G', 'T', 'T', 'A', 'A', 'G', 'G', 'C', 'T', 'G' ]
console.log(pAequor.mutate()) // logs for example [ 'G', 'T', 'T', 'T', 'G', 'G', 'T', 'T', 'A', 'A', 'G', 'G', 'C', 'T', 'G' ]

Note: Please format your code to make it easier for others to read it and help you
How do I format code in my posts?

Thank you very much! “console.log(pAequor.mutate())” it prints undefined, now i have to modify mutate i guess

1 Like

Yes, you need to write code inside the mutate() function body. I wasn’t sure where you were stuck: Understanding what mutate() should do or how to achieve that.
Try writing code for the method and if that still doesn’t work and you cannot debug it on your own, post your code here. But please make sure it is properly formatted and therefore readable.

1 Like