Please check if the code is correct?


#1

var slaying = true;
var youHit = Math.floor(Math.random() * 2);
var damageThisRound = Math.floor(Math.random()*5 +1);
var totalDamage = 0;
while (slaying) {
if (youHitl) {
console.log("You hit");
totalDamage += damageThisRound;
if (totalDamage >= 4){
console.log("You win");
slaying = false;
}
else {
youHit = Math.floor(Math.random() * 2);
}
}
else {
console.log("You lose");
slaying = false;
}
};

The error is "Make sure you log a message to the console!"

Here's the link -

https://www.codecademy.com/en/courses/javascript-beginner-en-mrTNH-6VIZ9/0/5?curriculum_id=506324b3a7dffd00020bf661#


#2

And if you look at the output window you see this error message:

ReferenceError: youHitl is not defined

youHitl, sounds like youHit but then with an additional l at the end, and indeed, in this line:

if (youHitl) {

you misspelled youHit


#3

Hi you wrote youHitl instead of youHit


#4

oops thanks for finding it.


#5

oops thanks for finding it. Thanks a lot :slightly_smiling: