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
(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)

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++) {
      newStrand.push(returnRandBase())
    }
    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());
console.log(test1);

//mutate test1
test1.mutate;
console.log(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:

console.log(test1.dna);
console.log(test1.mutate());
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