#5 Can someone help me spot my mistakes?


#1

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=1){
console.log("Good job!");
var totalDamage+=damageThisRound;
if(totalDamage>=4){
console.log("You slayed the dragon");
};
else{
console.log("You are defeated");
};
slaying=false
}
SyntaxError: Expected ';'


#2

I make a few changes and it still doesn't work.
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("Good job!");
totalDamage+=damageThisRound;
if(totalDamage>=4){
console.log("You slayed the dragon");
slaying=false;
}
else{
console.log("You are defeated");
slaying=false;
}
}
SyntaxError: Expected '}'


#3

Try to use this 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("Good job!");
totalDamage+=damageThisRound;
if(totalDamage>=4) {
console.log("You slayed the dragon");
slaying=false;
}
}
else {
console.log("You are defeated");
slaying=false;
}
}


#4

I solved it. Thank you