View Single Post
Old 09-14-2012, 02:42 AM   PM User | #3
rdspoons
New Coder

 
Join Date: Jun 2009
Posts: 81
Thanks: 0
Thanked 8 Times in 8 Posts
rdspoons is on a distinguished road
This may help. You can compare the code and the comments to your original code.
Code:
<HTML>
<body>
<script type="text/javascript">
//You may want to add your own default word for the prompt to 
//avoid the prompt's 'undefined' default.
var name=prompt("Hi. Whats your name?","friend")

var mood=prompt("Hi " + name + ". How are you?") //'undefined' is the default answer
var fine="fine"
var bad="bad"

//remember to put your conditional comparisons inside of parentheses.
if(mood==fine)
	alert("Im glad you are fine, " + name)
//you can use an if..else if.. else struture to allow a default 
//answer if neither 'fine' nor 'bad' are given as the response.
//dont' forget mood=bad is an asignment, not a comparison.
else if(mood==bad)
	alert("Ooo. Thats bad, Im sorry. I hope you get better, " + name)
//and maybe add a default greeting in case 'fine' or 'bad' are not entered
else
	alert("So..., it looks like you're in a " + mood +" mood, " + name)

//And don't forget to close the script tag
</script>

</body>
</SCRIPT>
</HTML>
rdspoons is offline   Reply With Quote
Users who have thanked rdspoons for this post:
jolimk (09-23-2012)