Dragon Slayer. Why > = 4?



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");
        if (totalDamage >= 4) {
            console.log ("you slew dragon");
            slaying = false;
    else {
        console.log ("zee dragon killed you");
   slaying = false;     


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)


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?


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