Dragon Slayer Game In JavaScript

  1. //   DRAGON SLAYER GAME IN JAVASCRIPT   
  2. var slaying = true;  
  3. var youHit = Math.floor(Math.random() * 2);  
  4. var damageThisRound = Math.floor(Math.random() * 5 + 1);  
  5. var totalDamage;  
  6. while(slaying)  
  7. {  
  8.     slaying = false;  
  9.     if(youHit = 1)  
  10.     {  
  11.         console.log("You hit the Dragon");  
  12.         totalDamage += damageThisRound;  
  13.         if(totalDamage >= 4)  
  14.         {  
  15.             console.log("The player slew the dragon.");  
  16.             slaying = false;  
  17.         }  
  18.         else  
  19.         {  
  20.             youHit = Math.floor(Math.random() * 2);  
  21.         }  
  22.     }  
  23.     else  
  24.     {  
  25.         console.log("The Dragon defeated you");  
  26.     }  
  27. }