Lesson 2, old enough to play?


Hi there,
I'd like you to see my code:

console.log("ready to play?");
confirm("I understand confirm!");
var age = "15";
var age = prompt("What's your age?");
if("age < 13")
console.log("You're allowed to play, but we'll take no responsibility!")

console.log("You're allowed to play on!")


when I'm typing 15 in response to the condition, I should have "You're allowed to play on!" shown on, instead of that, I have the same response, than if I had chosen "12" for an age!
I did miss something, but what?


This line is really unnecessary:

var age = "15";

In the next line you declare this variable again.

Problem is in your condition:

"age < 13"

This is a string. Any non empty string is evaluated as true. That is why this condition is always met.

What you wanted to do is:

age < 13

This is a boolean expression. Condition will be met only if value of variable age is less than 13 :slightly_smiling:


It works!
Thank you!


You're very welcome! :slightly_smiling:


I'm also having an issue with this one. Here's my code:

// Check if the user is ready to play!

confirm("I am ready to play");

var age = prompt("What's your age");

if (age < 13) 
    console.log("Your're allowed to play but we take no responsibility")
    console.log("Play on!")

It keeps asking me if I have set the variable equal to prompting the user for their age. I can't figure out what is wrong. Please help.