2.Declare your variables I do not know where the error


#1

2.Declare your variables
I do not know where the error ...

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

whenever I run the code appears on the display Syntax Error: Syntax error. I've reached all (think so).

var slaying = true;
var youHit = Math.floor(Math.random() *2);
var damageThisRound = Math.floor(Math.random() * 5 + 1);
var totalDamage = 0;
while (slaying) {
slaying = false;
if(youHit = 1) {
console.log("Você acertou o Dragão!");
totalDamage += damageThisRound;
if (totalDamage >= 4) {
console.log("O Dragão está morto e você conseguiu rodar o codigo!");
slaying = false;
} else {
youHit = Math.floor(Math.random() * 2);
} else {
console.log("O Dragão fritou você!");
}
}

`


#2

Where is the ending bracket for the while loop?? All the other functions have closing brackets except this one.


#3

Hi your code should have that structture

while (slaying) {#open the while statement
    if (condition) { #open the first if statement
        #do something
        if (codition) { #open the second if statement

        } #close the second if statement

        else { #open the first else statement

        } #close the first else statement
    }#close the first if statement

    else {#open the second else statement

   }#close the second else satement

}#close the while statement

and here

if(youHit = 1)

if you want to check equality you should use === instead of =


#4

I got it, but only by the code at the beginning:

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

thanks for the support and patience, anything back here to clear my doubt.


#5

thank you, had forgotten brackets.


#6

My conclusion to the dragon slayer! That is there:

var slaying = true;
var youHit = Math.floor(Math.random() *2);
var damageThisRound = Math.floor(Math.random()*5 + 2);
totalDamage = 0;
while(slaying) {
slaying = false;
}
if (youHit = 1) {console.log("Você acertou o Dragão!");
totalDamage += damageThisRound;} if(totalDamage >= 4)
{console.log("O Dragão fritou você!"); slaying = false;} else {console.log("O Dragão está morto e você conseguiu rodar o codigo!"); }


#7

I tried the code but it didn't work :3