Dragon Slayer!

I Putting an End to the Burnination
i. What you’ll be building 1/6
Save and Submit
ii. Declare your variables 2/6

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

iii. The ‘while’ loop 3/7

var slaying = true;
var youHit = Math.floor(Math.random() * 2);
var damageThisRound = Math.floor(Math.random()*5 + 1);
var totalDamage = 0;
while (slaying) {
    slaying = false;
}

iv. The first ‘if’ statement 4/6

var slaying = true;
var youHit = Math.floor(Math.random() * 2);
var damageThisRound = Math.floor(Math.random()*5 + 1);
var totalDamage = 0;
while (slaying) {
    if (youHit = 1) {
        console.log("Congratulations!You hit the dragon.");
    }
    else {
        console.log("The dragon defeated you.");
    } 
    slaying = false;
}

v. The second ‘if’ statement 5/6

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("Congratulations!You hit the dragon.");
        if (totalDamage >= 4) {
            console.log("Wao, you slew the dragon.");
            slaying = false;
        }
       else {
           youHit = Math.floor(Math.random() * 2);
       }
    }
    else {
        console.log("The dragon defeated you.");
    } 
    slaying = false;
}

vi. Well done! 6/6
Save & Submit

Advertisements

One thought on “Dragon Slayer!

  1. thank you so very much for all of your excellent work! what a huge help you have been to me and my fellow class mates!!!!!!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s