// DRAGON SLAYER GAME IN JAVASCRIPT
var slaying = true;
var youHit = Math.floor(Math.random() * 2);
var damageThisRound = Math.floor(Math.random() * 5 + 1);
var totalDamage;
while(slaying)
{
slaying = false;
if(youHit = 1)
{
console.log("You hit the Dragon");
totalDamage += damageThisRound;
if(totalDamage >= 4)
{
console.log("The player slew the dragon.");
slaying = false;
}
else
{
youHit = Math.floor(Math.random() * 2);
}
}
else
{
console.log("The Dragon defeated you");
}
}In this code snippet, we will be making a dragon slayer game in JavaScript.
