Jump to content

Prompt Dialog Box Problem!


gautamshaw
 Share

Recommended Posts

I am very new to Java Script.......i tried this code:<script language="javascript">function Dialog_Box(){ var a=confirm("Do you want to continue?") { if(a==true) { var b = prompt("Is 2 a prime number?","Answer") if(b!=null && b!="") { if(b.touppercase()=="Yes") { alert("You are right") } else { alert("You are wrong") } } } } }</script>But its not working properly.........i am having problems with the innermost if-else statement;i.e with this part of my code: if(b.touppercase()=="Yes") { alert("You are right") } else { alert("You are wrong") }If the user enters yes to the to the textbox present in the prompt dilog box then i want to show the alert("You are right") else alert("You are wrong")........i need some help in this.......thanks a lot

Link to comment
Share on other sites

i removed all the { }Here is my code:<script language="javascript">function Dialog_Box(){var a=confirm("Do you want to continue?")if(a==true)var b = prompt("Is 2 a prime number?","Yes or no?")if(b!=null && b!="") if(b.touppercase=="YES")alert("You are right")elsealert("You are wrong") }</script>Still it did not work properly

Link to comment
Share on other sites

you didn't need to remove all the {'s ad }'s, just the one before the first if statement,look at the following examples,

function wrong(){var wrongA=confirm("Is this wrong?");{if(wrongA=="true"){alert("Correct!")}else{alert("Wrong!")}}}function wright(){var wrightA=confirm("Is this wright?")if (wrightA=="true"){alert("Correct!")}else{alert("Wrong!")}}

see the difference?

Link to comment
Share on other sites

<script type="text/javascript">function Dialog_Box(){  var a=confirm("Do you want to continue?")  if(a==true)  {	var b = prompt("Is 2 a prime number?","Yes or no?")	if(b!=null && b!="") 	{	  if(b.toUpperCase()=="YES")		alert("You are right")	  else		alert("You are wrong") 	}  }}</script>

Indenting goes a long way towards helping you figure out the structure of the code.

Link to comment
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
 Share

×
×
  • Create New...