Wednesday, March 12, 2014

dragon slayer

var slaying=true; var youHit=Math.floor(Math.random()*2); var damageThisRound=Math.floor(Math.random()*5 + 1); var totalDamage=totalDamage+damageThisRound; while(slaying) { if (youHit===1) { console.log("you hit the dragon"); if (totalDamage>=4) { console.log("you slew the dragon!"); slaying=false; } else { youhit=Math.floor(Math.random()*2); } } else { console.log("the dragon burnates you, you are dead"); } slaying=false; } play this game on my site

1 comment:

  1. Take a look at the example linked off my home page (http://students.gctaa.net/~jelkner/) for examples of how to make these JavaScript programs run in a web page.

    ReplyDelete