Created
August 31, 2013 23:18
-
-
Save stevencombs/6401271 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
// 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