Advertisement
ohowell

Untitled

Apr 28th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. var slaying = true;
  2. var youHit = Math.floor(Math.random() * 2);
  3. var damageThisRound = Math.floor(Math.random() * 5 + 1);
  4. var totalDamage = 0;
  5.  
  6. while(slaying) {
  7. if(youHit) {
  8. console.log("Nice! You hit the dragon!");
  9. totalDamage += damageThisRound;
  10.  
  11. if(totalDamage >= 4) {
  12. console.log("Kablamo! You have slain the dragon!");
  13. slaying = false;
  14. } else {
  15. youHit = Math.floor(Math.random() * 2);
  16. }
  17. } else {
  18. console.log("Smooth move Ferguson. You missed and have been burnt to a crisp by the dragon");
  19. slaying = false;
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement