Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="description" content="[Control flow: if, else-if, else]">
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width">
  7. <title>JS Bin</title>
  8. </head>
  9. <body>
  10.  
  11. <script id="jsbin-javascript">
  12. //Control flow: if, else-if, else
  13. /* Allows to control the flow of an application.
  14. * Decisions are made in code by asking true or false questions.
  15. * Based on the answer, we decide what code runs if a statement
  16. * is true or false/
  17. */
  18. //IF, ELSE-IF, AND ELSE STATEMENTS
  19. /* To start a conditional, you use an IF statement.
  20. * You can chain as many ELSE IF statements as needed to initial
  21. * IF statement. The default ELSE statement is appended at the end of
  22. * the chain.
  23. *
  24. *
  25. * Anatomy: 1. Test condition in (). 2. BODY {} executed when condition
  26. * is true. BRACKETS MATTER AND INDENTATION IS CONVENTION
  27. */
  28. var condition = true;
  29. if(condition === true) {
  30. //do something if condition is true
  31. } else {
  32. //do something if condtion is false
  33. }
  34.  
  35. /* More questions can be chained together to give more options
  36. * to program flow.
  37. */
  38.  
  39. var color = "white";
  40. if(color === "white") {
  41. //do something
  42. } else if(color === "blue") {
  43. //do something
  44. } else {
  45. //do something
  46. }
  47. </script>
  48.  
  49.  
  50.  
  51. <script id="jsbin-source-javascript" type="text/javascript">//Control flow: if, else-if, else
  52. /* Allows to control the flow of an application.
  53. * Decisions are made in code by asking true or false questions.
  54. * Based on the answer, we decide what code runs if a statement
  55. * is true or false/
  56. */
  57. //IF, ELSE-IF, AND ELSE STATEMENTS
  58. /* To start a conditional, you use an IF statement.
  59. * You can chain as many ELSE IF statements as needed to initial
  60. * IF statement. The default ELSE statement is appended at the end of
  61. * the chain.
  62. *
  63. *
  64. * Anatomy: 1. Test condition in (). 2. BODY {} executed when condition
  65. * is true. BRACKETS MATTER AND INDENTATION IS CONVENTION
  66. */
  67. var condition = true;
  68. if(condition === true) {
  69. //do something if condition is true
  70. } else {
  71. //do something if condtion is false
  72. }
  73.  
  74. /* More questions can be chained together to give more options
  75. * to program flow.
  76. */
  77.  
  78. var color = "white";
  79. if(color === "white") {
  80. //do something
  81. } else if(color === "blue") {
  82. //do something
  83. } else {
  84. //do something
  85. }
  86. </script></body>
  87. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement