Would I use IF statements?


#1


https://www.codecademy.com/courses/javascript-beginner-en-mrTNH-6VIZ9/0/6?curriculum_id=506324b3a7dffd00020bf661


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;

while(slaying){
    if(youHit){
        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;


#2

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.


#3

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