Dragonslayer


#1

unexpected identifier

Replace this line with your code. 
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) {
        console.log( " YOU HIT THE DRAGON");
        
var totalDamage =+ damageThisRound 
    if (totalDamage >= 4 )
{console.log("You've Slaid the Dragon") slaying = false}
   } else{youHit = Math.floor(Math.random())} 
    else{console.log("You Lose") totalDamage += damageThisRound
    slaying = false;
    }
}


#2

Whats wrong with my code?
It keeps giving me unexpected identifier


#3

start by properly indenting your code, then you will see that one of your else is misplaced.


#4

thank you after properly indenting my code i saw that the first one of my else statement were misplaced.


#5

Okay, any questions or can you move on?

A good lesson in why indention is important


#6

no but a good refresher on how to properly indent would help.


#7

Indention is the choice of the developer. 4 spaces is most common, and then there are two main styles:

while(slaying){
    if (youHit) {
        console.log( " YOU HIT THE DRAGON");
    }
}

or the other style:

while(slaying)
{
    if (youHit) 
    {
        console.log( " YOU HIT THE DRAGON");
    }
}

#8

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