Boolean problem, always false


#1

No matter what answer you type for your age, it always end up displaying "let's start!" as if it was always false, why?

confirm("I am ready to play!");
var age = prompt("What's your age");
if( "age" < 13 )
{
    console.log("allowed to play but we don't take any responsability");
}
else
{
    console.log("let's start!");
}


#2

if( "age" < 13 ) // remove ""

you cant compare string vs number


#3

Take age out of quotes in the if statement. You're checking the variable, not comparing a string to an int.


#4

Remove the quotes from around age in your if statement.

With the quotes there, you are comparing the literal string "A-G-E". We want to compare the variable so we use age without quotes.


#5

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