What am i doing wrong here?


Old enough to play?

This will involve two pieces of code:
First we will use prompt to ask a user for their age, like this:
var age = prompt("What's your age");

The variable age will hold the user's response.

  1. Then we will use an if/else statement based on the age of the user. Here's an outline of the code, similar to what we've seen before:
    if(age is less than 13)
    // do this code
    else // "otherwise"
    // do this code


  1. Under the existing code, declare a variable age.
  2. Make age equal to prompt("What's your age");. See the example above.
  3. Then write an if/else statement. If age is less than 13, use console.log to tell the user that they're allowed to play but you take no responsibility.
  4. Else, use console.log and give them an encouraging message to play on!



Get live, fast support from Codecademy Advisors when you get stuck.
Learn more.

Recall the syntax for if / else statements.
if (condition) {
// code code code
} else {
// code code code

This is what I wrote------

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

if ( age less than 13)

{console.log ("they're allowed to play but you take no responsibility.")}


{console.log ("You can play, go on!")}


SyntaxError: Expected ')'


Inside your condition, you wrote 'age less than 13'. Javascript won't understand this. You need to use the comparison operator <.


in the 'if' block you've to use a operator '<' which is actually represents to 'less than' in the human readable form, Thus your code will be,

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

if ( age < 13)

{console.log ("they're allowed to play but you take no responsibility.");}


{console.log ("You can play, go on!");}


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