PDA

View Full Version : JavaScript alert box



thats all folks
March 19th, 2007, 08:20 PM
I was working on what seemed to be a simple alert/prompt box that asks a question and if the users answer in wrong it would say try again, but my script seems messed up. If anyone can help that would be great!!

Cheers

<script type="text/javascript" language="javascript1.5">
<!-- HIDE FROM OLDER BROWSER

var yourAns = prompt("Who Developed JavaScript?", "Enter Answer Here");
var ans = "Netscape";
var ans2 = "netscape";
if (yourAns == ans || yourAns == ans2 ){
alert("Your Right!!");
}
else {
alert("Try Again");
}

// -->
</script>

borrob
March 20th, 2007, 05:50 AM
i don't see the problem seems to be working fine. so what's the problem?

thats all folks
March 20th, 2007, 09:09 AM
borrob,

when the prompt box asks the question and you answer wrong it closes the prompt box, I need it to redisplay the prompt box asking to re-enter your answer if wrong and if right display yuour right in the prompt box.

Cheers

foodpk
March 20th, 2007, 09:46 AM
<script type="text/javascript">
function quiz() {
var yourAns = prompt("Who Developed JavaScript?", "Enter Answer Here");
var ans = "Netscape";
var ans2 = "netscape";
if (yourAns == ans || yourAns == ans2 ){
alert("Your Right!!");
}
else {
alert("Try Again");
quiz();
}
}
</script>



<body onload="quiz()">

I hope this is just for learning purposes and you're not seriously putting tihs on the net. :D

thats all folks
March 20th, 2007, 11:24 AM
foodpk,

no just for learning only!! Thanks
So much for the help!!!

Cheers