Dragon Slayer. Why > = 4?


#1


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


Nothing wrong with the code but just a general question. If it takes 4 hits to kill the dragon and 1 miss to die, why is the variable totalDamage set to >=4?


Replace this line with your code. 
var slaying = true;
var youHit = Math.floor(Math.random()*2);
var damageThisRound = Math.floor(Math.random()*5+1);
var totalDamage = 0;

while (slaying) {
    if (youHit) {
        console.log ("congrats! you hit zee dragon wahoo");
        totalDamage+=damageThisRound;
        if (totalDamage >= 4) {
            console.log ("you slew dragon");
            slaying = false;
        }
    }
    else {
        console.log ("zee dragon killed you");
   slaying = false;     
}
}


#2

because it was choosen this way

Who ever created the course decided this was a good balance (winning vs losing) when you design your own game, you can pick this balance (a game should be balanced)


#3

It is actually this way for an edge case where the damage dealt is greater than four. They're just checking that the damage dealt is at least four, not exactly four. Make sense?


#4

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