Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: My java programming wont work
05-14-2014, 06:31 PM #1
- Join Date
- May 2014
- Thanked 0 Times in 0 Posts
My java programming wont work
I am new to java. can someone tell me whats wrong
confirm("Are You Ready to Play")
age = prompt("What's your age?")
if(age < 13)
console.log("I take no responsibility")
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'");
var userAnswer = prompt("Do you want to race Bieber on stage?");
if(prompt = yes)
console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!");
console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");
05-14-2014, 06:40 PM #2
- Join Date
- Jun 2002
- London, England
- Thanked 2,599 Times in 2,577 Posts
Have you tried using your error console (F12 key)?
Suggest the following alterations:-
var ready = confirm("Are You Ready to Play",""); // all variables should be defined with the var keyword. (But whatever the answer the script proceeds)
var age = prompt("What's your age?", "") // Eliminate ugly "undefined" in prompt.
(But what if user responds "Mickey Mouse" or whatever (not a number)?)
var userAnswer = prompt("Do you want to race Bieber on stage?","");
if ( userAnswer == "yes" ) // = is assignment, == is comparison. "yes" must be in quotes as it is a literal string. if (userAnswer == yes) compares the answer with the value of a variable named yes (which does not exist).
(but what if user responds Yes or YES or Y?)
Be aware also that prompts and alerts are long obsolete, and should be used only for testing purposes. Not for obtaining responses from and/or displaying messages to your users.
Last edited by Philip M; 05-14-2014 at 07:59 PM.
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.