Would I use IF statements?



Nothing is wrong. I was wondering if I needed to use if/else statements to create a more immersive game. Let's say, it took 2 or 3+ hits to slay the dragon, but he also had the chance to hit you back. I would think you would need more variables ie; dragon damage, dragon miss, dragon hit, dragon wins. Then would I use if/else statements to let the game play out a little longer?

ar slaying = true;
var youHit = Math.floor(Math.random() *4);
var damageThisRound = Math.floor(Math.random() *10 + 2);
var totalDamage = 0;

        console.log("You Hit!");
        totalDamage += damageThisRound;
        if (totalDamage >= 8);
        console.log("You have slew the Dragon!");
        if (totalDamage < 8);
        console.log("You did not do enough damage");
    } else {
        console.log("You Missed!");
    slaying = false;


You certainly can. Give it a go, you simply need to follow the same concept as you did with this game. But you can essentially create a very long/ detailed text game just using if and else statements.


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