Dragon Slayer; Simpler/Better Syntax?


#1

Hi,
I am new to JS. Went through "Dragon Slayer" excerise and tried to come up with a better/simpler way to write the same game. Would you consider this code as effective as suggested by the CA author:

var slaying = true;
var youHit = Math.floor(Math.random() * 2);
var hitDamage = Math.floor(Math.random() * 5 + 1);

while(slaying){
if(youHit && hitDamage >= 4){
document.write("You killed the dragon!" + " Your Hit Damage was: " + "" + hitDamage + "");
slaying = false;
} else {
document.write("Dragon killed you!" + " Your Hit Damage was: " + "" + hitDamage + "" + " but you missed.");
slaying = false;
}
}

Thanks in advance!


#2

The code probaly works i didn't tried it but with JSit's easier to make it more complex and bigger and better.