2. Old enough to Play: Declaring Variable "age"


#1

I'm afraid I'm in dire need of assistance... I keep receiving the message "Did you define a variable called age?" where, as you can see, I have certainly attempted to do so.

function start () {
    println("Are. You. READY?!");
    confirm("Yeah, I'm ready!!");
    var age = prompt("What's your age");
    if( age > 13)
    {
        console.log("You can play but we can't accept responsibility.")
    }
    else
    {
        console.log("Let's go!")
    }
}

Could someone help me pinpoint what's exactly wrong with my code?


#2

reload your browser :slight_smile:
and you missed ; after console.log("Let's go!")
but what do you want to do?
its javascript not java.
if you want to print somethig in java you should use println
but in javascript you should use console.log
ok?
@electric294


#3

You confused Javascript with Java:

Should be

console.log("Are. You. READY?!");

println will give an error.
You should probably add semicolons to the end of the console.log statements in the if/else bit.


#4

Thank you guys, that makes a lot more sense as to why it wasn't quite running as expected, as I'm learning Java for a class, and I'd thought they were basically the same thing. XD Also, thank you for pointing out that I missed the semicolons. However, I've done all of these as well as refreshed the browser (Chrome) and it is still presenting the same error message, "Did you define a variable called age?" Here is what my code looks like now:

function start () {
console.log("Are. You. READY?!");
confirm("Yeah, I'm ready!!");
var age = prompt("What's your age");
if( age > 13)
{
console.log("You can play but we can't accept responsibility.");
}
else
{
console.log("Let's go!");
}
}

Any other suggestions?


#5

Thank you @rcodeman , I appreciate the help. :wink: As I said above, I'm taking classes for Java and thought they were the same thing. However, I'm afraid Codecademy is still presenting the same error message, "Did you create a variable called age?" Could you check out my newly edited code above and see if you could help me further here, please?


#7

Thank you @jibblyj I appreciate the help. :wink: As I've said earlier, I confused the two because I thought they were basically the same thing. XD Anyways, I did as suggested and I'm afraid it is still providing me with the same error message: "Did you remember to create a variable named age?" Could you take a look at the newly edited code above and help me further, please? Thanks!


#8

function start () {
    console.log("Are. You. READY?!");
    confirm("Yeah, I'm ready!!");
    var age = prompt("What's your age");
    if( age > 13){
        console.log("You can play but we can't accept responsibility.");
    }
    else {
        console.log("Let's go!");
    }
}

The code you posted is perfect - I formatted it above and I don't see a problem. Try reloading your browser now to see if it works.


#9

@jibblyj Well, I copied the formatting you provided, reloaded the page, brought it up in another tab, brought it up in a new window, and brought it up in Firefox... I'm afraid Codecademy is still providing the same error message: "Did you create a variable called age?" :sweat: I included a screenshot so you know what I'm referring to. :neutral_face:


#10

Ok, so I solved it by taking it all out of the function start(), like so:

Click me

console.log("Are. You. READY?!");
confirm("Yeah, I'm ready!!");
var age = prompt("What's your age");
if( age > 13){
    console.log("You can play but we can't accept responsibility.");
}
else {
    console.log("Let's go!");
}


#11

THANK YOU SOOOOO MUCH!! :sweat_smile: Taking out function start() worked! Now I can proceed. Thanks @jibblyj ! :grin: