Don´t understand why it doesn´t log a message to the console


#1


Don´t understand why it doesn´t log a message to the console....


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!";
}
else {
console.log="The Dragon defeated you.";
}
slaying = false;
}


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


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


Replace this line with your code.


#2

console.log="What?" The correct syntax is console.log("What you want to say")


#3

I changed it to console.log("What you want to say");
but don´t know why i should remove the } between my console.log and slaying=false

Still get the same message.... Grrrrrrrrrr


#4

Oh, I'm sorry, I didn't realize that you had that in a while loop. It's hard to read sometimes without spaces. That was my mistake. Are you sure you changed both console.logs? It should look like this:

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){
        console.log("You hit it!")
    }
    else
    {
        console.log("You're toast!")
    }
    slaying = false
}

#5

Thank you.
Now i have the folling 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){
console.log("You hit it!");
}
else
{
console.log("You're toast!");
}
slaying = false;
}
The Result is the following:
Oops, try again. Your code doesn't look quite right. Check the Hint if you need help!

And the console says: TypeError: console.log is not a function


#6

Try refreshing the page. That code works, and I don't see why it would throw a type error.


#7

Thank you very much. Now all is fine.


#8

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