Jump to content


confirm("Are you ready to play?")

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

if (age is less than 13)

{

    console.log("You are to young!")

}

else

{

    console.log("GREAT")

}

Edited by colonel_mortis
code tags

PC SPECS: Athlon 860k, MSI 380 4GB, 8GB memory, 1TB HDD, Fractal Design Core 1000

Link to comment
https://linustechtips.com/topic/476326-what-is-wrong-with-my-java-script/
Share on other sites

Link to post
Share on other sites

I'm not particularly great with code, but shouldn't it be like this:

confirm("Are you ready to play?")var age = prompt("What's your age");if (age < 13){    console.log("You are to young!");}else{    console.log("GREAT");}
Link to post
Share on other sites

confirm("Are you ready to play?")var age = prompt("What's your age");// I changed the line belowif (age < 13){    console.log("You are to young!")}else{    console.log("GREAT")}

Not a javascript guy but that looks fairly wrong to me, try this. Also try the other answer, add semicolons. Try codecademy for learning js

Link to post
Share on other sites

confirm("Are you ready to play?")var age = prompt("What's your age");// I changed the line belowif (age < 13){    console.log("You are to young!")}else{    console.log("GREAT")}

Not a javascript guy but that looks fairly wrong to me, try this. Also try the other answer, add semicolons. Try codecademy for learning js

 

Yeah, changed the "is less than" to "<" just after posting. Never used JS before, but using "is less than" seems wrong. 

Link to post
Share on other sites

confirm("Are you ready to play?")var age = prompt("What's your age");if (age is less than 13){    console.log("You are to young!")}else{    console.log("GREAT")}
confirm("Are you ready to play?")var age = prompt("What's your age");if (age < 13){    console.log("You are to young!")}else{    console.log("GREAT")}

Looks like you used pseudocode rather than writing what it would be in JS

Link to post
Share on other sites

confirm("Are you ready to play?");var age = prompt("What's your age");if (age < 13){    console.log("You are to young!");}else{    console.log("GREAT");}

The combined efforts from this thread: http://www.javascriptlint.com/online_lint.php jslint says its fine

Link to post
Share on other sites

<snip>

}

System.out.println("Are you ready to play?");

System.in(char) //not sure about this part. After four years (although not delving very deep, as they're high school classes) I have never seen a confirm method. You have to check what they input, and //make sure its the right value, int char, string etc.

I assume console log is the same as System.out.println...but one of us labeled this code wrong. I'm not sure whether you have a console class and defined the method log or..

Shipping sucks

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×