4.The first 'if' statement


#1


The first 'if' statement


SyntaxError: Unexpected token {


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


#2

solved
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("Congatulations! You hit the dragon.");
}
else {
console.log("My apologies. You have been slain by the dragon.");
}
slaying = false;
};


#3

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