5/6 Does your second 'if' statement check to see if totalDamage is greater than or equal to 4?


#1

I don't know why I keep recieving this error, again and again

var slaying= true;
var hitdragon=Math.floor(Math.random() *2);
var damageThisround=(Math.random()*5+1);
var totaldamage=0;
var youhit=Math.floor(Math.random()*2);
while(slaying) { if (youhit) {console.log("You hit the dragon!");
totaldamage+=damageThisround;

if(totaldamage>=4) { console.log("You slew the dragon!");

slaying= false;
}

} else {console.log("The dragon ripped you apart and pissed fire on your remains"); slaying=false;}
}


#2

I'm not certain, but it is possible that your variable "totaldamage" is not being recognized by whatever is auto-checking the code to see if you accomplished the task. Try making your variable fit the JavaScript rule of mixed case "totalDamage".


#3

Just going to ask... What is the variable "hitdragon" for? I see that all variables are needed, except for variable "hitdragon", nor was it needed in the directions.

The variable doesn't really make an error, but it's confusing.

The real problem that I think makes the error is that you have an extra bracket in your if/else statement that's inside your if statement.

You also have to add an else statement after your if/else statement that is inside the if statement. Having only an if statement will make it incomplete. An else statement must be added.


#4

I had the same error. The code check mechanism specifically wants you to name your totaldamage as "totalDamage". no other variable name is accepted (also tried it with "dmgTot")


#5

Yes, Codecademy is picky when saying to copy things. But I don't think "dmgTot" would work :grin:
It's funny though.