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)];
    };

    newDna.push(newBase);
  }

  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:

https://github.com/pkeen/MysteriousOrganism/blob/main/main.js

Hi here is my solution