Page 361 - Webapplication11_C11_Flipbook
P. 361

Example: To display one of the two alternate messages.

                   <!DOCTYPE HTML>
                   <HTML>

                   <HEAD>
                   <TITLE> if-else statement </TITLE>
                   </HEAD>

                   <BODY>
                   <SCRIPT>
                   var my_score = parseInt(prompt("Enter a score"));

                   passing_score = 60;
                   if(my_score >= passing_score)
                   {

                   alert("Congratulations on passing the exam");
                   }
                   else

                   {
                   alert("You failed, try harder next time");
                   }

                   </SCRIPT>
                   </BODY>

                   </HTML>
                 On running the above program, we get the following output:


















                 When you click on the “OK” button, with the message “this page says”. Then a new window opens, as shown below:


















                                                                                                  JavaScript Part 1  359
   356   357   358   359   360   361   362   363   364   365   366