Thanks, I’ll take a look at yours too. I take your point re: the variable names but I wanted to represent the bases they related to. I could have done with count_c for example but that was more typing
Hi I am Marion, this is my project for review:
I think you did 9-1 great. From a biological-view it completly makes sense and by the look of it, so does the code (but I’m a newby to:) )
here is my code:
Here is my attempt, thanks for taking a look.
Thanks to your solution of “30 instances” I understand how I need to do this. Thank you for sharing!
This challenge was so important in me actually understanding factory functions. Please let me know if you review and you see better ways I could improve my code. Thank you for your time
Before going through and optimizing with peers and AI, this was my initial code. I’ve since been able to update the compareDNA using the reduce() method, as well as simplify the chanceOfSurvival() and willeLikelySurvive() using the filter() method.
UPDATED CODE WITH CHANGES
This was such a difficult challenge! I think I’m going to need to go over this entire module again. I thought I was following along and understanding the concepts, but when it comes to these challenges/projects it’s like I’ve forgotten everything! Either way I think I managed to get through it and here is my code:
Hey Guys! HERE my solution.
Please, give me feedback.
Thanks
Hi everyone!
Here I’d like to share my solution for this challenge project. I tried to make all the requirements, including the extensions requirements. Although it was a long time to accomplish this challenge, I feel proud of my solution.
Please, feel free to see my solution and tell me if there is any improvement that I should make to improve my solution.
I hope that my attempt can help other students as well.
If there are doubts about my solution, I will feel happy to try to answer any question.
Sorry I don’t really know how to host on GitHub yet or send a file in the normal format like I see other posts on here, but can someone please explain to me why the below does not print anything? Just copy paste it onto the js part. I reduced the number of specimens it generates to 2 because the console seemed to be crashing from lack of memory to generate 30. I put console.log() both in the final function body and in the final line to get it to print something and it wouldn’t. Thanks
const returnRandBase = () => {
const dnaBases = [“A”, “T”, “C”, “G”];
return dnaBases[Math.floor(Math.random() * 4)];
};
const mockUpStrand = () => {
const newStrand = ;
for (let i = 0; i < 15; i++) {
newStrand.push(returnRandBase());
}
return newStrand;
};
function pAequorFactory(specimen, dnaSequence) {
const organism = {
_specimenNum: specimen,
_dna: dnaSequence,
mutate() {
let originalBaseIndex = this._dna[Math.floor(Math.random * 15)];
let originalBase = this._dna[originalBaseIndex];
let newBase = returnRandBase();
if (newBase === originalBase) {
newBase = returnRandBase();
} else {
this._dna[originalBaseIndex] = newBase;
}
},
compareDNA(newSpecimenDNA) {
let sameBases;
for (i = 0; i < this._dna.length; i++) {
if (this._dna[i] === newSpecimenDNA[i]) {
sameBases += 1;
}
let percentage = (sameBases / this._dna.length) * 100;
}
return ${organism} shares ${percentage}% of its DNA with the compared specimen
;
},
willLikelySurvive(dnaSequence) {
for (i = 0; i < this._dna.length; i++) {
let CG;
let likelySurvival;
if (this._dna[i] === “C” || this._dna[i] === “G”) {
CG += 1;
}
if (CG / this._dna.length >= 0.6) {
likelySurvival = true;
} else {
likelySurvival = false;
}
return likelySurvival;
}
},
};
return organism;
}
function strongPAequorGenerator() {
let strongpAequor = ;
let specimens = 0;
let specimenNumber = 1;
while (specimens < 2) {
let sampleOrganism = pAequorFactory(specimenNumber, mockUpStrand());
if (sampleOrganism.willLikelySurvive() === false) {
sampleOrganism.mutate();
} else {
specimens += 1;
specimenNumber += 1;
strongpAequor.push(specimenNumber);
}
}
return strongpAequor;
console.log(strongpAequor)
}
strongPAequorGenerator()
console.log(strongPAequorGenerator());
Your willLikelySurvive
method is not working correctly.
You declared the variable CG
inside the for-loop so it resets at each iteration of the loop (meaning CG
resets for each letter of the .dna
array).
To fix this, you should have let CG = 0;
before the for-loop, instead of having let CG;
inside the loop.
Use the </> button and paste the code on lines between the ``` and ``` to keep the formatting of your code in the post next time.
Hello there!!!
Here is my code.
The compareDNA method is modified so it could be used in the last project extension. The original requirement is still there as a comment.
Any feedback will be appreciated.
// 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;
};
let num = [];
function pAequorFactory(specimenNum, DNA) {
return {
_specimenNum: specimenNum,
_DNA: DNA,
get DNA() {
return this._DNA;
},
set DNA(newDNA) {
this._DNA = newDNA;
},
get specimenNum() {
return this._specimenNum;
},
set specimenNum(newspecimenNum) {
if (num.includes(newspecimenNum)) {
console.log("The number you entered already exists");
} else {
num.push(newspecimenNum);
this._specimenNum = newspecimenNum;
}
},
mutate() {
const dnaBases = ["A", "T", "C", "G"];
const randomIndex = Math.floor(Math.random() * this._DNA.length);
console.log(randomIndex);
const correntBase = this._DNA[randomIndex];
let newIndex = correntBase;
while (newIndex === correntBase) {
newIndex = dnaBases[Math.floor(Math.random() * 4)];
}
this._DNA[randomIndex] = newIndex;
return this._DNA;
},
compareDNA(secondDNA){
let dup = 0;
for(let i = 0; i< this._DNA.length;i++){
if(this._DNA[i] == secondDNA.DNA[i]){
dup++;
}
}
console.log(dup);
let result = Math.floor(dup / 15 *100);
console.log(`specimen #${this._specimenNum} and specimen #${secondDNA.specimenNum} have ${result}% DNA in common`);
},
willLikelySurvive(){
let count= 0;
for(let i = 0; i < this._DNA.length; i++){
if(this._DNA[i] == "C" || this._DNA[i] == "G"){
count++;
}
}
if(count >= 9){
return true;
}else {
return false;
}
}
};
}
const examples = [];
/*const test1 = pAequorFactory(1, mockUpStrand());
const test2 = pAequorFactory(2, mockUpStrand());
console.log(test1.DNA + "\n" + test2.DNA)
console.log(test2.willLikelySurvive());
*/
let c = 1;
while(c < 31){
let i = 1;
const newEXP = pAequorFactory(i, mockUpStrand());
if(newEXP.willLikelySurvive()){
examples.push(newEXP)
c++;
}
i++;
}
console.log(examples.length);
I’m sorry but I don’t understand this project I’ve read this a million times and gone over the javaScript section a billion times and I seriously don’t understand this section what does it want me to do. im sorry if i seem dumb maybe I am but I don’t even know how to start.
Please take a look and give any feedback you like!
Hello All!
Finally, I finished this project. My code is here : Mysterious Organism
Please share your comments to improve it. Thanks!
Hi everyone. I just completed this wonderful project. Please feel free to help me review and give me a feedback.
Here is a link to my code: Codecademy export · GitHub