Flash Games
 FAQ   Search   Memberlist   Usergroups   Register  Profile   Log in to check your private messages   Log in 


alert, prompt, and confirm, if/else statements



 

Post new topic   Reply to topic  
   DEVPPL Forum Index -> JavaScript Forum
View previous topic :: View next topic  
Author Message
babii_kaikz



Joined: 19 Oct 2007
Posts: 1

PostPosted: Fri Oct 19, 2007 4:15 pm    Post subject: alert, prompt, and confirm, if/else statements Reply with quote

consider this general question:

Arrow what comes after the letter c in the alphabet Question

answer is : d.

how can i check to see if the answer is correct or not without using a form, but using the alert,prompt, confirm methods. how would i incorporate the if/else statements Confused

<script>
alert("what comes after the letter c in the alphabet?");
prompt("please enter the correct answer");
confirm("are you sure that is correct?");
if(...)
{
alert("that is correct");
}
else
{
alert("that is not correct");
}
</script>

what am i missing or doing incorrectly?


feedback is greatly appreciated Very Happy
Back to top
View user's profile Send private message
sachav



Joined: 03 Mar 2007
Posts: 32

PostPosted: Fri Nov 09, 2007 6:21 pm    Post subject: Re: alert, prompt, and confirm, if/else statements Reply with quote

You have to use a var "chars" into your code, for the client to recognize the alphabet (yes, stupid as it is, a computer does not know the alphabet!)
You also have to assign a variable to the answer.
So your code would be:

<script>
chars="abcdefghijklmnopqrstuvwxyz"
alert("what comes after the letter c in the alphabet?");
answer = prompt("please enter the correct answer","");
confirm("are you sure that is correct?");
reponseEnNombre=chars.indexOf("c",0)
reponseEnNombrePlusUn=(reponseEnNombre+(1*1))*1
if(chars.charAt(reponseEnNombrePlusUn)==answer.charAt(0))
{
alert("that is correct");
}
else
{
alert("that is not correct");
}
</script>


Or you can even make a random letter:
(a little bit harder):


<script>
chars="abcdefghijklmnopqrstuvwxyz"
random=Math.round(Math.random()*chars.length)
letterChosen=chars.charAt(random)
alert("what comes after the letter "+letterChosen+" in the alphabet?","");
answer = prompt("please enter the correct answer");
confirm("are you sure that is correct?");
reponseEnNombre=chars.indexOf(letterChosen,0)
reponseEnNombrePlusUn=(reponseEnNombre+(1*1))*1
if(chars.charAt(reponseEnNombrePlusUn)==answer.charAt(0))
{
alert("that is correct");
}
else
{
alert("that is not correct");
}
</script>
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    DEVPPL Forum Index -> JavaScript Forum All times are GMT + 1 Hour
Page 1 of 1

 
 
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User: Pass:
Log me on automatically each visit:

 


Powered by phpBB © 2001, 2005 phpBB Group - Modified by DEVPPL

Flash Games - Sitemap