Dragon Slayer, how to make the dragon counter?



Hi, I am trying to create a way in which after your initial damage has been dealt, if you haven't outright killed the dragon, he will counter attack you for large amount for damage, yet there is an open piece of script somewhere which crashes my browser. Plus this script seems quite messy, I was just wondering how would I clean this up and finish the script so that it is working? Thank you.

confirm ("Are you ready for an adventure?")
var choice = prompt ("You have encountered a dragon! Do you RUN or FIGHT?");
if (choice === "RUN") {
    console.log ("You try to run but the dragon is too quick as it charges you down to block your exit. Your only choice is to fight!");
} else {
    console.log ("You draw your sword, take down this beast!")
var dragonCounter = true;
var slaying = true;
while(slaying) {
    if (youHit) {
    console.log("You hit the dragon for " + damageThisRound + " damage!");
    totalDamage += damageThisRound;
    if (totalDamage >= 4) {
        console.log("You have slain the dragon!")
        slaying = false;
    } else {
        youHit = Math.floor(Math.random() * 2);
    } else {
        console.log ("You only dealt " + damageThisRound + " damage, the dragon shrugs off your attack and releases a flame breath attack!");
        while (dragonCounter) {
            if (dragonHit) {
                console.log ("The Dragon hit you for " + dragonDamageThisRound + " damage!");
                totalDragonDamage += DragonDamageThisRound;
                if (totalDragonDamage >= 3) {
                    console.log ("You have been killed!");
                    dragonCounter = false;
                } else {
                    console.log ("You survived the first attack, but only just! You must quickly make an escape. This is a fight for another day...");
    slaying = false;
    dragonCounter = false;
var youHit = Math.floor(Math.random()* 2);
var damageThisRound = Math.floor(Math.random()* 5 + 1);
var totalDamage = 0;
var dragonHit = Math.floor(Math.random()* 2);
var dragonDamageThisRound = Math.floor(Math.random()* 19 + 1);
var totalDragonDamage = 0;


i would first define the variable (youHit, damageThisRound) and then your game logic.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.