Created
November 26, 2013 14:48
-
-
Save born2frag/7659558 to your computer and use it in GitHub Desktop.
Small JS dragon game with loops (if,while,for)
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; | |
var youHit = Math.floor(Math.random()*2); | |
var damageThisRound = Math.floor(Math.random()*2); | |
var totalDamage = 0; | |
while(slaying) | |
{ | |
if(youHit) | |
{ | |
console.log("Nice - you've just hit black dragon"); | |
totalDamage += damageThisRound; | |
if(totalDamage>=4) | |
{ | |
console.log("HOLY SHIT - YOU JUST KILL A DRAGON") | |
slaying = false; | |
} | |
else | |
{ | |
youHit = Math.floor(Math.random() * 2); | |
} | |
} | |
else | |
{ | |
console.log("You missed the dragon - that means you dead") | |
} | |
slaying = false; | |
} | |
console.log(youHit); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment