5/6 Reference Error


#1

So I got my code to work, but I have a ReferenceError saying that "damageThisRound" is not defined. I'm not sure where I went wrong, but if someone could just point me in the right direction, it would be much appreciated :smile:

My code looks like this

var slaying = true;
var youHit = Math.floor(Math.random() * 2);
var damangeThisRound = Math.floor(Math.random() *5 + 1);
var totalDamage = 0;
while(slaying) {
if(youHit) {
console.log("You hit the dragon!");
totalDamage += damageThisRound;
if(totalDamage >= 4) {
console.log("You Win!");
slaying = false;
} else {
youHit = Math.floor(Math.random() * 2);
}
}
else {
console.log("You missed the dragon!");
slaying = false;
}
}


#2

ReferenceErrors are often caused by variables that are used before they were declared and if you're pretty sure that you declared it yet, then most of the time it is a typo :smile:
In this case you added an n here:

var dama n geThisRound = Math.floor(Math.random() *5 + 1);