I can't understand why this isn't working please help!


#1



Plz help I can't understand why this code isn't working I have checked my code numerous times for syntax errors but have been unable to find anything.

SyntaxError: Unexpected identifier


var slaying=true;
var youHit=Math.floor(Math.random()*2);
var totalDamage=0;
var damageThisRound=Math.floor(Math.random()*5+1);
while(slaying){
    if (youHit){
        console.log('you hit the dragon');
        damageThisRound=Math.floor(Math.random()*5+1);
        totalDamage=totalDamage+damageThisRound;
        if totalDamage>=4{
            slaying=false;
            console.log('The draong has been slain');
        }else{
            youHit=Math.floor(Math.random()*2);
        }
    }else{
        console.log('the dragon ate you');
        slaying=false;
    }
}


#2

You forgot about parentheses after the if.


#3

Thank you! I can't believe that I missed that ... stupid mistake on my part there.


#4

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