Mysterious Organism - mutate function

Hi all.
JS has got me feeling like the thickest person in the world.
I have got as far as what I think the mutate function should look like

But I’m not clear on 1) whether I’m testing it properly (you can see my attempts at test at the bottom), and 2) if I am indeed testing it properly, where I’m going wrong.

I’m drawing such a blank here guys, and I’d love some input.

Big love.

// 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++) {
    return newStrand

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

//mutate function
        mutate () {
            const randIndex = Math.floor(Math.random() * this.dna.length);
            let newBase = returnRandBase();

//to compare the dna base at the random index with newBase (a randomly generated base), and if they're the same, redo the step until they're not the same. 
            while (this.dna[randIndex] === newBase) {
                newBase = returnRandBase();
//reassign the randIndex base as the newBase
              this.dna[randIndex] = newBase;
              return this.dna;

//variable test1
const test1 = pAequorFactory(1,mockUpStrand());

//mutate test1

Hey there,
don’t worry, that’s a complicated one, and it looks quite well already!
If you just fix a few things in your testings, you’ll see a reasonable result (I haven’t tested if the mutate function follows the instructions, but the result looks like it does).

Don’t just test the the factory function. That just returns the function itself:

mutate is a method, you need to invoke it (add parenthesis):

To test it, log the result of the mutation (test1.mutate()) rather than just test1.

In order to compare the strands, you could log:

1 Like

Thank you so much Mirja!!
It works now :slight_smile:
Thank you for explaining where i’d slipped up so clearly
Have a great day

1 Like