4.The first 'if' statement


#1

It keeps on giving me the same pop-up message.

https://www.codecademy.com/courses/javascript-beginner-en-mrTNH-6VIZ9/0/4?curriculum_id=506324b3a7dffd00020bf661#

Make sure you log a message to the console to let the player knows if (s)he won or lost!

var slaying = false;
var youHit = Math.floor(Math.random()*2)
var damageThisRound = Math.floor(Math.random()*5 + 1)
var totalDamage = 0;

while(slaying){
    console("Die you mythical beast?")
        
        if(true === 1 > 0) {
            console.log("Congratulations for killing the dreaded Bargoth the dark prevalour")
            }
            else{
    console.log("You are defeated by the dragon,so don't get up")
                }
                slaying = true;
    }

#2

this line:

if(true === 1 > 0)

the comparison is wrong. You are comparing two things (if 1 equals true, and if 1 is great then 0), if you want to do multiply comparisons, use a and (&&) or or (||) operator.

But you should do neither if those things, you should see if youHit is true (1) or false (0)


#3

Cool thnks a Million! Solved it

~~~~
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!");
} else {
console.log("You missed!");
}
slaying = true;
}

~~~~


#4

nope it didnt pass ...not solved!


#5

your slaying is currently false. should be true. then false further down

right now you are saying.. while slaying is false( to me it translates, while we are not slaying). how can we then hit if we arent slaying. hope this makes sense

so ..

var slaying = true;

then after you run your program you want it to stop

slaying = false;


#6

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