Syntax error: Unexpected token { . What's wrong with my code? It looks the same with the code in the Hint but I'm still getting that error


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

The second ‘if’ statement

<In what way does your code behave incorrectly? Include ALL error messages.>

Syntax error: Unexpected token { .

```

var slaying = true;
var youHit = Math.floor(Math.random()*2);
var youDamage = Math.floor(Math.random()*5+1);
var totalDamage = 0;

while(slaying)
{
if(youHit)
{
console.log(“You hit the dragon”);
totalDamage += damageThisRound;
if(totaDamage>=4)
{
console.log( " You did this to the dragon");
slaying=false;
}
else if
{
youHit=Math.floor(Math.random()*2) ;
}

else
{
    console.log("The dragon defeat you");
    slaying = false;
}

}
}

<do not remove the three backticks above>Continuing the discussion from [Unexpected token {](https://discuss.codecademy.com/t/unexpected-token/35183):

#2

You have problems on the positions of your curly brackets. hope this helps:

while(){  //open curly bracket of your WHILE

    if(){ //open curly bracket of your FIRST IF
        if(){ //open curly bracket of your IF inside your FIRST IF
            } //close curly bracket of your IF inside your FIRST IF
        else{  //open curly bracket of your ELSE inside your FIRST IF
            } //close curly bracket of your ELSE inside your FIRST IF
        } //close curly bracket of your FIRST IF

    else{ //open curly bracket of your ELSE
        } //close curly bracket of your ELSE

    } //close curly bracket of your WHILE

And one more thing, on this line:

You must declare the variable damageThisRound above instead of youDamage;


#3

thank you so much @gracie017


#4

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