Hi everyone! I decided to do the Project Extensions… …second one was tough, but I got through it! So yeah Task 9.1 and 9.2 are included. Have a look if you’re interested
Challenge Project: Mysterious Organism | JavaScript Workspace | Codecademy
Hi everyone! I decided to do the Project Extensions… …second one was tough, but I got through it! So yeah Task 9.1 and 9.2 are included. Have a look if you’re interested
Challenge Project: Mysterious Organism | JavaScript Workspace | Codecademy
Ha! Love that you count how many didn’t make it…
Did spot a little mistake in your complementStrand()
method I think. Have a look; think you’ll see it right away
And I actually managed to wrestle through 9.2! So yeah have a look if you’re interested
You are right, I mess up by duplicating A to T I’ll check your solutions to 9.2. To be honest, I had no idea how to start that part.
Bingo! I had some idea… made me think of the mutual followers exercise we encountered in the course. With the nested for-loops. But yeah this was a tough one!
Feel free to ask for clarification if you want
const bobsFollowers = ['Alex', 'David', 'Andre', 'Maurice'];
const tinasFollowers = ['Angelique', 'Andre', 'Maurice'];
const mutualFollowers = [];
for (let b = 0; b < bobsFollowers.length; b++) {
for (let t = 0; t < tinasFollowers.length; t++) {
if (bobsFollowers[b] === tinasFollowers[t]) {
mutualFollowers.push(tinasFollowers[t]);
}
}
}
console.log(mutualFollowers);
Hey guys here is my solution. Feedback will be appreciated.
Attaching my solution on GitHub. This project was quite challenging for me because objects are the most complicated topic. Glad to get some new knowledge during this process.
Hope to get a review from someone more(or even less) experienced!
I like this project.
Here’s my solution.
(first time using gist)
Hello, this is my solution. If there’s anything that could be improved, please let me know! Codecademy export · GitHub
Hi all,
And here is my Gist for this project:
It was quite challenging, took me some time, but in the end I managed to do everything without the hints!
I would really appreciate if you could have a look and tell me where I can improve my code!
Thank you,
Marion
Hi everyone,
here’s my gist for this project.
It was quite challenging for me I must admit so I would really appreciate your help to see how I could improve this.
Thanks yall
Link to my solution for this project
Would definitely say the thing that made this project a little tricky is the names and the instructions were somewhat unclear in the first few steps. I figured it out though. Didn’t do the bonus portion though may come back to that in a bit.
My commenting could be much more thorough in this one but I’m happy with the code. Not to toot my own horn but I thought using a do while
to check that the mutated base was actually different was pretty elegant.
// 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
}
// create a pAequor simulation object
const pAequorFactory = (specimenNum, dna) => {
return {
specimenNum,
dna,
mutate() {
rndNo = Math.floor(Math.random() * 15);
const oldBase = this.dna[rndNo];
let newBase = '';
do {
newBase = returnRandBase();
// console.log(`oldBase: ${oldBase}, newBase: ${newBase}`);
} while (newBase === oldBase);
this.dna[rndNo] = newBase;
return this.dna;
},
compareDNA(pAequor) {
// console.log(this.dna);
// console.log(pAequor.dna);
const sharedBases = this.dna.map((base, index) => {
if (base === pAequor.dna[index]) {
return 1;
} else {
return 0;
}
});
console.log(`Specimine #${this.specimenNum} and #${pAequor.specimenNum} share ${((sharedBases.reduce((currentValue, accumulator) => currentValue + accumulator)/15)*100).toFixed(2)}% of their DNA.`);
},
willLikelySurvive() {
let C = 0;
let G = 0;
for (const base of this.dna) {
switch (base) {
case 'C':
C++;
break;
case 'G':
G++;
break;
default:
break;
}
}
// console.log(`% of C: ${(C/15).toFixed(1)*100} - % of G: ${(G/15).toFixed(1)*100}`);
if ((C/15) >= 0.6 || (G/15) >=0.6) {
return true;
} else {
return false;
}
return false;
}
}
}
const samples = [
pAequorFactory(0, [ 'A', 'G', 'G', 'A', 'C', 'G', 'G', 'A', 'C', 'T', 'A', 'A', 'A', 'T', 'T' ]),
pAequorFactory(1, [ 'G', 'G', 'T', 'G', 'G', 'A', 'G', 'G', 'G', 'C', 'C', 'G', 'A', 'G', 'T' ]),
pAequorFactory(2, [ 'T', 'T', 'T', 'T', 'C', 'A', 'G', 'C', 'T', 'T', 'G', 'T', 'T', 'T', 'G' ]),
pAequorFactory(3, [ 'A', 'G', 'G', 'T', 'T', 'C', 'A', 'T', 'A', 'C', 'G', 'C', 'T', 'T', 'G' ]),
pAequorFactory(4, [ 'C', 'C', 'T', 'A', 'C', 'T', 'C', 'C', 'G', 'A', 'C', 'C', 'T', 'C', 'C' ]),
pAequorFactory(5, [ 'G', 'T', 'C', 'T', 'A', 'C', 'A', 'A', 'T', 'A', 'G', 'T', 'C', 'A', 'A' ])
];
console.log('----- Start of fixed samples tests -----');
// check if any of the manually generated samples will survive
samples.forEach(sample => console.log(`spacimen ${sample.specimenNum} likely survive: ${sample.willLikelySurvive()}`));
samples[0].compareDNA(samples[1]);
samples[1].compareDNA(samples[2]);
samples[2].compareDNA(samples[3]);
samples[3].compareDNA(samples[4]);
samples[4].compareDNA(samples[5]);
console.log(`sample 5's dna
${samples[5].dna}`);
console.log(`sample 5 mutated
${samples[5].mutate()}`);
samples[4].compareDNA(samples[5]);
const genPAequai = (log = false) => {
const pAequai = [];
for (let i = 0; i < 30; i++){
pAequai.push(pAequorFactory(i, mockUpStrand()));
}
// if log parameter is set to true log the array to console
if (log) console.log(pAequai);
return pAequai;
}
console.log();
console.log('----- Start of randomly generated samples -----');
console.log();
// generate array of pAequor samples
const pAequai = genPAequai();
pAequai[0].compareDNA(pAequai[1]);
console.log(pAequai[0].willLikelySurvive());
console.log(pAequai[0].dna);
console.log(pAequai[0].mutate());
// pAequai.forEach(pAequor => console.log(pAequor.dna));
I have included my solution here.
Let me know if you have questions or ideas to improve.
This is how I solved it.
If there’s anything that could be improved, please let me know!
Hello everyone,
I need review for my solution to the exercice.
Please let me now if you have any suggestion or appreciation !
Good days to everyone
Here is my project
Be free to ask any questions you may have!
It looks nice! Something small I would change is the name of the C
and G
variables in the willLikelySurvive()
method since it’s generally not considered good practice to use single-letter names for variables outside of loops and math calculations. However, this doesn’t affect the functionality of the code, so great job! ^^
Hello! Just completed this task, I’m not sure about task 9-1 because there isn’t any picture by the link provided, so I tried my best from google, so if I’m wrong in execution 9-1, please share an explanation and I’ll rewrite it quickly.
For now, I have a working js script here
As always any feedback appreciate