Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. /*Control flow: if, else-if, else
  12. +If statements test if a condition is true, and execute something if
  13. true. */
  14. "use strict";
  15.  
  16. var number = 8;
  17. function test1(num) {
  18. if (num > 5) {
  19. return "greater than five";
  20. }
  21. }
  22. console.log(test1(number)); //returns "greater than five"
  23. /* +If-else statements return something if the condition is met, and
  24. return something else if not met. */
  25. function test2(num) {
  26. if (num > 5) {
  27. return "greater than five";
  28. } else {
  29. return "less than five";
  30. }
  31. }
  32. console.log(test2(number)); //returns "greater than five"
  33. /*+Else-if statements test if a first condition is true, and if false
  34. evaluates a second condition. If neither are true, it executes the
  35. default, if written in, or nothing if not. */
  36. function test3(num) {
  37. if (num < 5) {
  38. return "less than five";
  39. } else if (num - 5 < 5) {
  40. return "not more than nine";
  41. }
  42. }
  43. console.log(test3(number)); //returns "not more than nine"
  44. /* +"else" can be used as a default to execute if none of the conditions
  45. are met. */
  46. function test4(num) {
  47. if (num < 5) {
  48. return "less than five";
  49. } else {
  50. return "greater than five";
  51. }
  52. }
  53. console.log(test4(number)); //returns "greater than five"
  54. /*+If statements can be nested, so that if the first condition is met,
  55. it will enter into the next if statement to test. */
  56. function test5(num) {
  57. if (num > 5) {
  58. if (num < 10) {
  59. return "greater than five but less than ten";
  60. }
  61. }
  62. }
  63. console.log(test5(number)); //returns "greater than five but less than ten"
  64. /* Conditions are always evaluated from top to bottom. Two or more
  65. conditions can also be combined into one test using logical operators. */
  66. function test6(num) {
  67. if (num > 0 && num < 10) {
  68. return "number between one and nine";
  69. }
  70. }
  71. console.log(test6(number)); //returns "number between one and nine"
  72. </script>
  73.  
  74.  
  75.  
  76. <script id="jsbin-source-javascript" type="text/javascript">/*Control flow: if, else-if, else
  77. +If statements test if a condition is true, and execute something if
  78. true. */
  79. var number = 8
  80. function test1(num) {
  81. if(num > 5) {
  82. return "greater than five";
  83. }
  84. }
  85. console.log(test1(number)); //returns "greater than five"
  86. /* +If-else statements return something if the condition is met, and
  87. return something else if not met. */
  88. function test2(num) {
  89. if(num > 5) {
  90. return "greater than five";
  91. } else {
  92. return "less than five";
  93. }
  94. }
  95. console.log(test2(number)); //returns "greater than five"
  96. /*+Else-if statements test if a first condition is true, and if false
  97. evaluates a second condition. If neither are true, it executes the
  98. default, if written in, or nothing if not. */
  99. function test3(num) {
  100. if(num < 5) {
  101. return "less than five";
  102. } else if(num - 5 < 5) {
  103. return "not more than nine";
  104. }
  105. }
  106. console.log(test3(number)); //returns "not more than nine"
  107. /* +"else" can be used as a default to execute if none of the conditions
  108. are met. */
  109. function test4(num) {
  110. if(num < 5) {
  111. return "less than five";
  112. } else {
  113. return "greater than five";
  114. }
  115. }
  116. console.log(test4(number)); //returns "greater than five"
  117. /*+If statements can be nested, so that if the first condition is met,
  118. it will enter into the next if statement to test. */
  119. function test5(num) {
  120. if(num > 5) {
  121. if(num < 10){
  122. return "greater than five but less than ten";
  123. }
  124. }
  125. }
  126. console.log(test5(number)); //returns "greater than five but less than ten"
  127. /* Conditions are always evaluated from top to bottom. Two or more
  128. conditions can also be combined into one test using logical operators. */
  129. function test6(num) {
  130. if(num > 0 && num < 10) {
  131. return "number between one and nine";
  132. }
  133. }
  134. console.log(test6(number)); //returns "number between one and nine"</script></body>
  135. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement