Posted By

shanegriff on 06/22/08


Tagged

javascript Switch case if else statement


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

SpinZ


Javascript IF Statements


 / Published in: JavaScript
 

  1. <html>
  2. <head>
  3. <script language="javascript">
  4.  
  5. var secret_password = "jasmine";
  6. var entered_password = prompt("please enter password", " ");
  7.  
  8. if (entered_password != secret_password)
  9. {
  10. document.write("incorrect");
  11. }
  12. else
  13. {
  14. document.write("welcome");
  15. }
  16.  
  17. </script>
  18. </head>
  19. <body>
  20.  
  21. </body>
  22. </html>
  23.  
  24.  
  25.  
  26. <html>
  27. <head>
  28. <script language="javascript">
  29.  
  30. var secret_password = "jasmine";
  31. var usernmae = "password";
  32. var entered_password = prompt("please enter password", " ");
  33. var entered_username = prompt("please enter username", " ");
  34.  
  35. if ((entered_password == secret_password) && (entered_username == username))
  36. {
  37. document.write("correct");
  38. }
  39. else
  40. {
  41. document.write("try again");
  42. }
  43.  
  44. </script>
  45. </head>
  46. <body>
  47.  
  48. </body>
  49. </html>
  50.  
  51.  
  52.  
  53. <html>
  54. <head>
  55. <script language="javascript">
  56.  
  57. var admin = admin
  58. var developer = "mike";
  59. var user = "user";
  60.  
  61. var entered_password = prompt("please enter password", " ");
  62.  
  63. switch (entered_password)
  64. {
  65. case "admin": alert("you are admin"); break
  66. case "mike": alert("you are a developer"); break
  67. case "user": alert("you are a user"); break
  68. default: alert("password Incorrect!!"); break
  69. }
  70.  
  71. </script>
  72. </head>
  73. <body>
  74.  
  75. </body>
  76. </html>

Report this snippet  

You need to login to post a comment.