Skip to content

Instantly share code, notes, and snippets.

@born2frag
Created November 26, 2013 14:48
Show Gist options
  • Save born2frag/7659558 to your computer and use it in GitHub Desktop.
Save born2frag/7659558 to your computer and use it in GitHub Desktop.
Small JS dragon game with loops (if,while,for)
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