What's wrong with my second if statement?


#1

I keep pressing on save and submit and it keep giving me this message, “Oops, try again. Does your second ‘if’ statement check to see if totalDamage is greater than or equal to 4?” I reaaly don’t know what’s wrong and I need help. Thanks!


var slaying = true;
var youHit = Math.floor(Math.random() * 2);
var damadgeThisRound = Math.floor(Math.random()*5 + 1);
var totalDamadge = 2;

while (slaying) {
  if (youHit) {
       console.log("You Hit!");
       totalDamadge += damadgeThisRound;

        if (totalDamadge >= 4) {
           console.log("Congrats! You slew the Dragon.");
           slaying = false;
       } else {
           youHit = Math.floor(Math.random() * 2);
       }
   } else {
       console.log("You missed!");
        slaying = false;
   }
}
 



#2

Hi @mariam_saleh,

Notice the spelling :wink:

var slaying = true;
var youHit = Math.floor(Math.random() * 2);
var damadgeThisRound = Math.floor(Math.random()*5 + 1); //<=== Spelling
var totalDamadge = 2; //<============================= Spelling

while (slaying) {
  if (youHit) {
       console.log("You Hit!");
       totalDamadge += damadgeThisRound; //<============== Spelling

        if (totalDamadge >= 4) {   //<================= Spelling
           console.log("Congrats! You slew the Dragon.");
           slaying = false;
       } else {
           youHit = Math.floor(Math.random() * 2);
       }
   } else {
       console.log("You missed!");
        slaying = false;
   }
}
 

As the error you got:

“Oops, try again. Does your second ‘if’ statement check to see if totalDamage is greater than or equal to 4?”

The checking system might be looking for totalDamage and damageThisRound, the spelling without the ‘d’.

Correct the spelling, then I think you’re good to go.

Cheers :slight_smile:


#3

Thank you so much! I finally got what’s wrong :slight_smile:


#4

You’re welcome. :slight_smile:


#5

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