Skip to content

Instantly share code, notes, and snippets.

@stevencombs
Created August 31, 2013 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevencombs/6401271 to your computer and use it in GitHub Desktop.
Save stevencombs/6401271 to your computer and use it in GitHub Desktop.
// Javascript Getting Started with Programming
// A Codecademy Javascript (Dragon Slayer!) assignment
// Dr. Steven B. Combs, coding novice
var slaying = true;
var youHit = Math.floor(Math.random() * 2); // random number between 0 and 1
var damageThisRound = Math.floor(Math.random() * 5 + 1); // random number between 1 and 5
var totalDamage = 0; // damage counter
while (slaying){
if (youHit == 1) {
console.log("YOU HIT THE DRAGON!");
totalDamage += damageThisRound;
if (totalDamage >= 4) { // total damage greater than 4
console.log("YOU HAVE SLAIN THE DRAGON!"); // game over
slaying = false;
} else {
youHit = Math.floor(Math.random() *2); // reset random hit
}
} else {
console.log("DRAGON IS VICTORIOUS!");
}
slaying = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment