Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-19-2013, 04:50 AM   PM User | #1
jenbaby12
New to the CF scene

 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
jenbaby12 is an unknown quantity at this point
If/Else statements not executing!

When I run the code all that runs are the prompts. Both true and false conditions will not execute.

<html>
<head>
<title>My Script</title>
<script type="text/javascript">

confirm("I'm ready to play!");

var age=prompt("What's your age?");
if(age > = 18 ){
console.log ("You may play, but we take no resposibility");
}else{
console.log ("play on");}
console.log("Snow White and Batman were hanging out at the bus stop, waiting to go to the shops. There was a sale on and both needed some new threads. You've never really liked Batman. You walk up to him.");
console.log("Batman glares at you.");
var userAnswer= confirm("Are you feeling lucky, punk?");

if(userAnswer==="yes"){
console.log("Batman hits you very hard. It's Batman and you're you! Of course Batman wins!");
}else{
console.log("You did not say yes to feeling lucky. Good choice! You are a winner in the game of not getting beaten up by Batman.");
}
var feedback=prompt("Please rate this game 1-10");
if (feedback < = 8){
console.log("This is just the beginning of my game empire. Stay tuned for more!");
}else{
console.log("I slaved away at this game and you gave me that score?! The nerve! Just you wait!");
}

</script>
</head>
<body>
</body>
</html>
jenbaby12 is offline   Reply With Quote
Old 02-19-2013, 08:18 AM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,455
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Have you opened the console to check what error messages are being written there if your log messages are not being written there?
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 02-19-2013, 09:07 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
3 to 1 odds he has no idea where the console *IS*.

jenbaby: In any case, the operators >= and <= can *NOT* have a space before the = sign.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

Last edited by Old Pedant; 02-19-2013 at 09:11 PM..
Old Pedant is offline   Reply With Quote
Old 02-20-2013, 09:41 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,038
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
And please read the form guidelines about the use of code tags. Putting your message in big red characters turns people off (it did me - I just moved on!) and is considered boorish.

if(userAnswer==="yes"){

What if the user types Yes, y or Y?

But I see that your userAnswer comes from a confirm box so is true or false, not yes or no.

if(age > = 18 ){

What is the user answers "Mickey Mouse"?

var feedback=prompt("Please rate this game 1-10");

What if the user enters -10 (my evaluation, I am afraid! )
__________________

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.

Last edited by Philip M; 02-20-2013 at 09:47 AM..
Philip M is offline   Reply With Quote
Old 02-20-2013, 12:55 PM   PM User | #5
Entity_
New Coder

 
Join Date: Dec 2012
Location: Ingerlund
Posts: 62
Thanks: 8
Thanked 4 Times in 4 Posts
Entity_ is an unknown quantity at this point
Hello good sir. For everyone else on here, I apologize profusely if I give this guy a wrong answer. I just feel I have to contribute something instead of just asking questions!

Firstly, this game seems to be the only game I've ever seen that issues a warning only if you are over 18, and secondly the whole problem with the code is simply as Old Pedant already said, the spaces between the > and =. Change that and it should work.


EDIT: I'm assuming this is for some sort of learning exercise so I didn't attempt to try and 'improve' your code.
Entity_ is offline   Reply With Quote
Old 02-20-2013, 01:02 PM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,038
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by Entity_ View Post
Firstly, this game seems to be the only game I've ever seen that issues a warning only if you are over 18
Well, you would have to be pretty juvenile to see anything interesting in this "game".
__________________

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.
Philip M is offline   Reply With Quote
Old 02-20-2013, 01:06 PM   PM User | #7
Entity_
New Coder

 
Join Date: Dec 2012
Location: Ingerlund
Posts: 62
Thanks: 8
Thanked 4 Times in 4 Posts
Entity_ is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
Well, you would have to be pretty juvenile to see anything interesting in this "game".
GOTY dude, have faith. I'm submitting this to kickstarter.
Entity_ is offline   Reply With Quote
Reply

Bookmarks

Tags
if/else statement, javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:57 PM.


Advertisement
Log in to turn off these ads.