Codecademy Mysterious Organism Project

This is my code. I’m only getting ‘false’ printed for my ‘willLikelySurvive()’ method. Please look over my code and tell me how it looks and what I can do to have it print ‘true’ as well as ‘false’. After this, I only have the last task which is to add the array that stores 30 instances of pAequor values.

if (baseC >= sixtyP || baseG >= sixtyP) {

baseC + baseG can be 15 max. So it can never be 60+. Either multiply (baseC + baseG) by 100 as well or don’t multiply by 100 anywhere.

So it should be:

let sixtyP = (baseC + baseG) * 100 / this.dna.length * 100;

?

No. That line was fine. It will result to the percentage of baceC + baseG in relation to dna.length – not necessarily to 60%. So I would rename the variable to ‘percentage’, for example:

let percentage = (baseC + baseG) / this.dna.length * 100;

Then you want to know whether ‘percentage’ is beyond or below 60, right?
So this line does not make sense:

if (baseC >= sixtyP || baseG >= sixtyP) {

baseC >= sixtyP can never be true because baseC will be 15 max.

I changed my variable to percentage and I changed my ‘if’ statement to be if (percentage >= 60). It is now printing true and false at random. Thank you!

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.