Mysterious Organism Challenge Project (JavaScript)

Hi folks ! Here is my solution until point 8.
Your comments are welcomed :slight_smile:

// 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 } function pAequorFactory(specimenNum , dna) { return { specimenNum, dna, mutate () { const index=Math.floor(Math.random() * 15); let newbase=returnRandBase(); while (newbase===this.dna[index]) { newbase=returnRandBase(); }; this.dna[index]=newbase; return this.dna; }, compareDNA (pAequor) { let count = 0; for (let i=0;i<pAequor.dna.length-1;i++) { if (pAequor.dna[i]===this.dna[i]) count++; } const commonDnaPct=(100*count/pAequor.dna.length).toFixed(); return `specimen ${this.specimenNum} and specimen ${pAequor.specimenNum} have ${commonDnaPct}% DNA`; }, willLikelySurvive() { let count = 0; for (let i=0;i<this.dna.length-1;i++) { const currentbase=this.dna[i]; if (currentbase==='C'||currentbase==='G') count++; }; const result = Math.floor(100*count/this.dna.length); return (result>=60); } }; } const pAequor = pAequorFactory(1, mockUpStrand()); console.log(pAequor); const pAequor2 = pAequorFactory(2, pAequor.mutate()); console.log(pAequor2); console.log(pAequor.compareDNA(pAequor2)); const pAequor3 = pAequorFactory(3, [ 'G', 'G', 'A', 'C', 'C', 'C', 'C', 'C', 'A', 'C', 'C', 'T', 'T', 'T', 'A' ] ); console.log(pAequor3.willLikelySurvive()); const pAequorArrayToStudy = []; for (let i=0; i<30; i++) { let newpAequor = pAequorFactory(i+1, mockUpStrand()); while (!newpAequor.willLikelySurvive()) newpAequor = pAequorFactory(i+1, mockUpStrand()); pAequorArrayToStudy.push(newpAequor); } console.log(pAequorArrayToStudy);
1 Like

Hello friends! :sunglasses:

Review my code about this challenge project, I’d be happy to know if you have some feedback for me Check my Gist.

Bye bye world!.

here is my soultion to the mutate problem, what you want to do is create 4 if statements or a switch statement for each case, and generate a replacement for the chosen strand to mutate, via math.floor(math.random() * 3)), inside a for loop that runs 15 times. let me just paste my code.

mutate () {
let newDna = ;

  for (let i = 0; i < 15; i++) {
    const dnaBases = ['A', 'T', 'C', 'G'];
    let baseToEdit = dnaBases[Math.floor(Math.random() * 4)];
    let availableBases;
    let newBase;

    if (baseToEdit === 'A') {
      availableBases = ['T', 'C', 'G'];
      newBase = availableBases[Math.floor(Math.random() * 3)];

    if (baseToEdit === 'T') {
      availableBases = ['A', 'C', 'G'];
      newBase = availableBases[Math.floor(Math.random() * 3)];

    if (baseToEdit === 'C') {
      availableBases = ['T', 'A', 'G'];
      newBase = availableBases[Math.floor(Math.random() * 3)];

    if (baseToEdit === 'G') {
      availableBases = ['T', 'C', 'A'];
      newBase = availableBases[Math.floor(Math.random() * 3)];


  return newDna;

here is my take on this challenge, this was definitely a difficult challenge. It took me 3 days to complete. I am looking forward to your feedback.

Access The Code Here!

Poorly formulated question. Guys(Codecademy)- you should provide an example/sample data set of what the input and output of a function should be. Confusing mutate() problem is not clear.
#1 . Are we just changing 1 random base in a 15 base strand? If so, specimen #1 and specimen #2 have 25% DNA in common will always be true ; Exactly how many random bases in a 15base strand are we supposed to change?
#2. specimen #1 = any unique mockUpStrand() and specimen#2 = the one obtained from mutate() function?

#3 " 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*."* what do you mean? for this example 'A cannot appear more than once in a 15 base strand --OR-- if ‘A’ is found in index 7 than ‘A’ cannot exist in any location 7 thru 15??? clear explanation needed

1 Like

Here’s my solution:

Hi here is my solution

Finally I managed to complete this challenge mostly using ChatGPT.
I have to say JS is a really tough language to learn compared to HTML and CSS.

Here is my code took me a couple hours, similar to the solution, but with a couple difference in the way i implemented it, it works just fine!. You can see in my .mutate( ) I took a weird path; didn’t realized it could’ve been as straightforward as the one in the solution, but it gets the job done!

My work space →

Hey Guys! here’s a link to mine.
had to check a few of your projects to be sure of what I’m doing

Hi, this is my solution.

Hello all.

I have finished the project and believe my code to be correct (if not optimal) in the terms of the challenge.

Here is a link:

Would appreciate any constructive feedback.

I’ve left in various statements I’d used to test the code, and directed the output to a text file so I could search it with grep, as was going crazy looking at all those ACTG’s. :slight_smile:

I would appreciate feedbacks

Alrock Mysterious Organism

My solution :slight_smile:

mystery-organism-starter at main · GitHub

Here is my solution.

Good day guys,

Here’s my solution.

here is my solution feel free to check it out :slight_smile: and don’t forget to leave me a feedback!