2. declare your variables


#1

Stuck here, could someone help me ? Thx.

var slaying = true;
var youHit = Math.floor(mathRandom() *2 );
var damageThisRound = Mathfloor(Mathrandom() * 5 + 2);
var totalDamage = 0;
while (slaying === true); {
slaying = false;
}
if (youHit = 1) {
console.log("Hai colpito il dragone !");
totalDamage+=damageThisRound;
}
if(totalDamage>=4); {
console.log("Il dragone è morto");
slaying=false;
}
else {
console.log("Il dragone ti ha colpito, auguri !");
}


#2

What are you having trouble with? What errors if any? I already see that you should have:

Math.random()

and

Math.floor()

#3

it says : syntax problem I changed, but still not working. thx for help

var slaying = true;
var youHit = Math.floor(Math.random() * 2 );
var damageThisRound = Math.floor(Math.random() * 5 + 1);
var totalDamage = 0;
while (slaying === true); {
slaying = false;
}
if (youHit = 1) {
console.log("Hai colpito il dragone !");
totalDamage+=damageThisRound;
}
if(totalDamage>=4); {
console.log("Il dragone è morto");
slaying=false;
}
else {
console.log("Il dragone ti ha colpito, auguri !");
}


#4

Remove the ; from between ) and { in your if statement.

if(1 === 1){
    console.log("Yes!");
}

#5

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