Message does not come up whether they won or lost


#1

var slaying = true
var youHit = Math.floor(Math.random() * 2)
var damageThisRound = Math.floor(Math.random()*5 + 1)
var totalDamage = 0
var slaying = true;
while(slaying) {
slaying = false;
}
while(slaying) {
if (youHit) {
console.log("You slayed the dragon!");
} else {
console.log("The Dragon Burries You!");
}
slaying = false;
}

I am stumped i don't know what to do


#2

if (youHit) {

The console is checking to see if this variable is true or false (1 or 0). Try giving it a value to compare against,

if (youHit < 1) {

Now it'll compare actual numbers to the variable "youHit".


#3

Didnt work it still said message doesnt come up when then won or lost


#4

var slaying = true
var youHit = Math.floor(Math.random() * 2)
var damageThisRound = Math.floor(Math.random()*5 + 1)
var totalDamage = 0
var slaying = true;
while(slaying) {
slaying = false;
}
while(slaying) {
if (youHit < 1) {
console.log("You slayed the dragon!");
} else {
console.log("The Dragon Burns You!");
}
slaying = false;
}

Does not work


#5

I can't get it to work either..


#6

`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 slayed the dragon!");
} else {
console.log("The Dragon Burns You!");
}
slaying = false;
}`
Here is the new code it works


#7

This was my code:

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

#8

Here look my 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 < 1) {
console.log("You slayed the dragon!");
totalDamage += damageThisRound
if (totalDamage >= 4) {
console.log("The dragon is defeated")
slaying = false
} else {
youHit = Math.floor(Math.random() * 2);
}
}else{
console.log("The Dragon Burns You!");
console.log("The Dragon killed you");
slaying = false;
}
slaying = false;
}`
Mine works see what you have done wrong and that you got wrong


#9

I'm going to do this lesson over again lol. It's quite a mess. :laughing:


#10

Just put my code in it is correct


#11

I've done that
all it says is: Unexpected token ILLEGAL