Trying to improve more-Syntax error


#1


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


I'm getting syntax errors that I can't find. I'm new to this so I'm sure I messed up. Please correct it or tell me where to correct. The idea is that if dragonShield is set to false, it runs Math.random() and if it is less than .34, it checks if dragonHelm is set to true. If it is, it sets it to false, gives you a message, and reruns the code. If not, the dragon kills you. It is the same with the chest and boots. I was trying to use an if/else/else if statement but i think I did it wrong.

My current error is SyntaxError: Unexpected token else

This is not relevant at all as I already completed the lesson.


var slaying = true
var youHit = Math.floor(Math.random()*2)
var damageThisRound=Math.floor(Math.random()*4)
var totalDamage=0
var dragonShield = true
var dragonHelm=true
var dragonChest=true
var dragonBoots=true
while(slaying){
    if(youHit===1){
        console.log("Congrats! You hit the dragon for"+ " " + damageThisRound);
        totalDamage += damageThisRound;
        if (totalDamage>=4){
            console.log("You slew the dragon!");
            slaying=false;
        }
        else{
            youHit = Math.floor(Math.random()*2);
        }
    }else{
        if(dragonShield==true){
            console.log("saved by your shield");
            dragonShield = false;
            youHit = Math.floor(Math.random()*2);
        }else{
            if(Math.random<.34){
                if(dragonHelm){
                    console.log("Saved by your helm!");
                    dragonHelm=false;
                    youHit = Math.floor(Math.random()*2);
                }else{
                    console.log("The dragon killed you!");
                    slaying = false;
                }
            else if(Math.random<.67){
                if(dragonChest){
                    console.log("Saved by your chestplate!");
                    dragonChest=false;
                    Math.floor(Math.random()*2);
                }else if{
                    console.log("The dragon killed you!");
                    slaying = false;
                }
            else{
                if(dragonBoots){
                    console.log("Saved by your boots!");
                    dragonBoots=false;
                    Math.floor(Math.random()*2);
                }else{
                    console.log("The dragon killed you!");
                    slaying=false;
                }
            }
        }
    }
}


#2

This dont can work. Else if or if or delete the condition


#3

Nevermind!! you helped me fix it and find the syntax error.


#4

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