Is not working


#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)
console.log("you hit");
}else{
console.log("You missed !");
slaying=false ;}

SyntaxError: Unexpected token else


Replace this line with your code.


#2

@vasilisbil04,
The error is caused
by you not using an opening-curly-bracket-{ after your IF condition
--
you are also not closing the WHILE statement with its own closing-curly-bracket-}

The structurre should look like

while ( condition ) {
   if ( condition ) {
       //your code in the IF code-block
   }
   else {
       //your code in the ELSE code-block
   }
}

#3

thank you that is the problem