Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Four Functions</title>
  5. </head>
  6. <body>
  7. <h1> Only use JavaScript and the console today! </h1>
  8. <script id="jsbin-javascript">
  9. /*
  10. #1 Triple Function
  11.  
  12. Directions: Make a function that triples a number.
  13. Example: If the parameter is 10, the function should return 30, because 10 * 3 = 30.
  14. Instructions:
  15. 1. Declare a function called triple. It should have one parameter.
  16. 2. In the body of the function, make a return statement that multiplies the parameter by 3.
  17. 3. Use console.log to test calling the function. Try using a small number!
  18. */
  19. //To do: Insert you code below this line
  20. var V = 10;
  21. function triple(V){
  22. console.log(V * 3);
  23. }
  24. triple(V);
  25. /*
  26. #2 Cubed Function
  27.  
  28. Directions: Make a function that returns the cubed value of the parameter.
  29. Example: If the parameter is 2, the function should return 8 because 2 * 2 * 2 = 8.
  30. Instructions:
  31.  
  32. 1. Declare a function called cubed. It should have one parameter.
  33. 2. In the body of the function, make a return statement that multiplies the parameter by itself 3 times.
  34. 3. Use console.log to test calling the function. Try using a small number like 2 or 3 to see if it works!
  35.  
  36. */
  37. //To do: Insert you code below this line
  38. var Y = 35;
  39. function cubed(Y){
  40. console.log(Y * Y * Y);
  41. }
  42. cubed(Y);
  43.  
  44.  
  45.  
  46. /*
  47. #3 Hello Name Function
  48.  
  49. Directions: Make a program that says hello to 3 different people.
  50. Example: If the parameter is "Erica", the function should return "Hello Erica"
  51.  
  52. Instructions:
  53. 1. Declare a function called greeting. Give the function one parameter.
  54. 2. In the body of the function, make a return statement with the string hello added to the parameter.
  55. 3. Using console.log, test a function call with your name. Do this 3 more times with other names!
  56. */
  57. //To do: Insert you code below this line
  58. function greeting(Mom){
  59. console.log("Hello"+" "+ Mom);
  60. }
  61. greeting("Rosa");
  62.  
  63.  
  64. /*
  65. #4 Average Function
  66.  
  67. Directions: Make a function that computes the average of two numbers.
  68. Example: If 6 and 10 are the parameters, the function should return 8 because (6 + 10)/2 = 8.
  69. Instructions:
  70. 1. Create a function called average with two parameters.
  71. 2. In the body of the function, make a return statement that calculates the average of two numbers.
  72. 3. Using console.log, test your function call with 6 and 10. Try it with two other numbers.
  73. */
  74. //To do: Insert you code below this line
  75. var x = 7;
  76. var y = 23;
  77. function average(x,y){
  78. console.log(x+y/2);
  79. }
  80. average(x,y);
  81. </script>
  82.  
  83. <script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
  84. <html>
  85. <head>
  86. <title>Four Functions</title>
  87. </head>
  88. <body>
  89. <h1> Only use JavaScript and the console today! </h1>
  90. </body>
  91. </html>
  92. </script>
  93.  
  94.  
  95. <script id="jsbin-source-javascript" type="text/javascript">/*
  96. #1 Triple Function
  97.  
  98. Directions: Make a function that triples a number.
  99. Example: If the parameter is 10, the function should return 30, because 10 * 3 = 30.
  100. Instructions:
  101. 1. Declare a function called triple. It should have one parameter.
  102. 2. In the body of the function, make a return statement that multiplies the parameter by 3.
  103. 3. Use console.log to test calling the function. Try using a small number!
  104. */
  105. //To do: Insert you code below this line
  106. var V = 10;
  107. function triple(V){
  108. console.log(V * 3);
  109. }
  110. triple(V);
  111. /*
  112. #2 Cubed Function
  113.  
  114. Directions: Make a function that returns the cubed value of the parameter.
  115. Example: If the parameter is 2, the function should return 8 because 2 * 2 * 2 = 8.
  116. Instructions:
  117.  
  118. 1. Declare a function called cubed. It should have one parameter.
  119. 2. In the body of the function, make a return statement that multiplies the parameter by itself 3 times.
  120. 3. Use console.log to test calling the function. Try using a small number like 2 or 3 to see if it works!
  121.  
  122. */
  123. //To do: Insert you code below this line
  124. var Y = 35;
  125. function cubed(Y){
  126. console.log(Y * Y * Y);
  127. }
  128. cubed(Y);
  129.  
  130.  
  131.  
  132. /*
  133. #3 Hello Name Function
  134.  
  135. Directions: Make a program that says hello to 3 different people.
  136. Example: If the parameter is "Erica", the function should return "Hello Erica"
  137.  
  138. Instructions:
  139. 1. Declare a function called greeting. Give the function one parameter.
  140. 2. In the body of the function, make a return statement with the string hello added to the parameter.
  141. 3. Using console.log, test a function call with your name. Do this 3 more times with other names!
  142. */
  143. //To do: Insert you code below this line
  144. function greeting(Mom){
  145. console.log("Hello"+" "+ Mom);
  146. }
  147. greeting("Rosa");
  148.  
  149.  
  150. /*
  151. #4 Average Function
  152.  
  153. Directions: Make a function that computes the average of two numbers.
  154. Example: If 6 and 10 are the parameters, the function should return 8 because (6 + 10)/2 = 8.
  155. Instructions:
  156. 1. Create a function called average with two parameters.
  157. 2. In the body of the function, make a return statement that calculates the average of two numbers.
  158. 3. Using console.log, test your function call with 6 and 10. Try it with two other numbers.
  159. */
  160. //To do: Insert you code below this line
  161. var x = 7;
  162. var y = 23;
  163. function average(x,y){
  164. console.log(x+y/2);
  165. }
  166. average(x,y);
  167. </script></body>
  168. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement