Created
August 10, 2016 23:43
-
-
Save Jingram17/6c2742e6cc67ffd92d3f73fcae04f594 to your computer and use it in GitHub Desktop.
This file contains 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 = Math.floor(Math.random() * 2); | |
var damageThisRound = Math.floor(Math.random() * 5 + 1); | |
var totalDamage = 0; | |
while (slaying) { | |
if (youHit) { | |
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 { | |
youHit = Math.floor(Math.random() * 2); | |
} | |
} else { | |
console.log("The dragon burninates you! You're toast."); | |
slaying = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment