I would like to know if someone knows my problem


#1

the script is as follows

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 the dragon");
totalDamage += damageThisRound;
if(tatolDamage >= 4) {
console.log("slew the dragon and set");
}
else{
youHit = Math.floor(Math.random()
}
}
else {
console.log("dragon defeated you");
}
slaying = false;
}


#2

@grunwoldab,

Have a close look at

tatolDamage


#3

this is the error message that i'm receiving
Oops, try again. There was a problem with your syntax.

this is my new script and it still not working

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 the dragon");
totalDamage += damageThisRound;
if(totalDamage >= 4) {
console.log("slew the dragon and set");
}
else{
youHit = Math.floor(Math.random();
}
} else {
console.log("You lose!");
}
slaying = false;
}


#4

should be

if( youHit ) {


#5

hi leon! thanks but it's still not working.
the script is as follows

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 the dragon");
totalDamage += damageThisRound;
if(totalDamage >= 4) {
console.log("slew the dragon and set");
}
else{
youHit = Math.floor(Math.random();
}
} else {
console.log("You lose!");
}
slaying = false;
}


#6

@grunwoldab
Change your

if(youHit === 1) {
and
youHit = Math.floor(Math.random();

INTO

if(youHit) {
and
youHit = Math.floor(Math.random()*2);


#7

like this? because still not working

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) {
youHit = Math.floor(Math.random()*2);
console.log("you hit the dragon");
totalDamage += damageThisRound;
if(totalDamage >= 4) {
console.log("slew the dragon and set");
}
else{
youHit = Math.floor(Math.random();
}
} else {
console.log("You lose!");
}
slaying = false;
}


#8

You're missing another bracket at the end of this.

youHit = Math.floor(Math.random());


#9

thanks that was the problem now it's working:grinning::grinning::laughing: