-
-
Save ravinggenius/86ea9278e29fce438aedd5739c38a031 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var slaying = true; | |
// A bit of new math magic to calculate the odds | |
// of hitting the dragon. We'll cover this soon! | |
var youHit; | |
var damageThisRound; | |
var totalDamage = 0; | |
do { | |
youHit = Math.floor(Math.random() * 2); | |
if (youHit) { | |
damageThisRound = Math.floor(Math.random() * 5 + 1); | |
console.log("You hit the dragon and did " + damageThisRound + " damage!"); | |
totalDamage += damageThisRound; | |
if (totalDamage >= 4) { | |
console.log("You did it! You slew the dragon!"); | |
slaying = false; | |
} | |
} else { | |
console.log("The dragon burninates you! You're toast."); | |
slaying = false; | |
} | |
} while (slaying) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment