Skip to content

Instantly share code, notes, and snippets.

@Jingram17
Created August 10, 2016 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Jingram17/6c2742e6cc67ffd92d3f73fcae04f594 to your computer and use it in GitHub Desktop.
Save Jingram17/6c2742e6cc67ffd92d3f73fcae04f594 to your computer and use it in GitHub Desktop.
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