Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Four Functions</title>
- </head>
- <body>
- <h1> Only use JavaScript and the console today! </h1>
- <script id="jsbin-javascript">
- /*
- #1 Triple Function
- Directions: Make a function that triples a number.
- Example: If the parameter is 10, the function should return 30, because 10 * 3 = 30.
- Instructions:
- 1. Declare a function called triple. It should have one parameter.
- 2. In the body of the function, make a return statement that multiplies the parameter by 3.
- 3. Use console.log to test calling the function. Try using a small number!
- */
- //To do: Insert you code below this line
- var V = 10;
- function triple(V){
- console.log(V * 3);
- }
- triple(V);
- /*
- #2 Cubed Function
- Directions: Make a function that returns the cubed value of the parameter.
- Example: If the parameter is 2, the function should return 8 because 2 * 2 * 2 = 8.
- Instructions:
- 1. Declare a function called cubed. It should have one parameter.
- 2. In the body of the function, make a return statement that multiplies the parameter by itself 3 times.
- 3. Use console.log to test calling the function. Try using a small number like 2 or 3 to see if it works!
- */
- //To do: Insert you code below this line
- var Y = 35;
- function cubed(Y){
- console.log(Y * Y * Y);
- }
- cubed(Y);
- /*
- #3 Hello Name Function
- Directions: Make a program that says hello to 3 different people.
- Example: If the parameter is "Erica", the function should return "Hello Erica"
- Instructions:
- 1. Declare a function called greeting. Give the function one parameter.
- 2. In the body of the function, make a return statement with the string hello added to the parameter.
- 3. Using console.log, test a function call with your name. Do this 3 more times with other names!
- */
- //To do: Insert you code below this line
- function greeting(Mom){
- console.log("Hello"+" "+ Mom);
- }
- greeting("Rosa");
- /*
- #4 Average Function
- Directions: Make a function that computes the average of two numbers.
- Example: If 6 and 10 are the parameters, the function should return 8 because (6 + 10)/2 = 8.
- Instructions:
- 1. Create a function called average with two parameters.
- 2. In the body of the function, make a return statement that calculates the average of two numbers.
- 3. Using console.log, test your function call with 6 and 10. Try it with two other numbers.
- */
- //To do: Insert you code below this line
- var x = 7;
- var y = 23;
- function average(x,y){
- console.log(x+y/2);
- }
- average(x,y);
- </script>
- <script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
- <html>
- <head>
- <title>Four Functions</title>
- </head>
- <body>
- <h1> Only use JavaScript and the console today! </h1>
- </body>
- </html>
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">/*
- #1 Triple Function
- Directions: Make a function that triples a number.
- Example: If the parameter is 10, the function should return 30, because 10 * 3 = 30.
- Instructions:
- 1. Declare a function called triple. It should have one parameter.
- 2. In the body of the function, make a return statement that multiplies the parameter by 3.
- 3. Use console.log to test calling the function. Try using a small number!
- */
- //To do: Insert you code below this line
- var V = 10;
- function triple(V){
- console.log(V * 3);
- }
- triple(V);
- /*
- #2 Cubed Function
- Directions: Make a function that returns the cubed value of the parameter.
- Example: If the parameter is 2, the function should return 8 because 2 * 2 * 2 = 8.
- Instructions:
- 1. Declare a function called cubed. It should have one parameter.
- 2. In the body of the function, make a return statement that multiplies the parameter by itself 3 times.
- 3. Use console.log to test calling the function. Try using a small number like 2 or 3 to see if it works!
- */
- //To do: Insert you code below this line
- var Y = 35;
- function cubed(Y){
- console.log(Y * Y * Y);
- }
- cubed(Y);
- /*
- #3 Hello Name Function
- Directions: Make a program that says hello to 3 different people.
- Example: If the parameter is "Erica", the function should return "Hello Erica"
- Instructions:
- 1. Declare a function called greeting. Give the function one parameter.
- 2. In the body of the function, make a return statement with the string hello added to the parameter.
- 3. Using console.log, test a function call with your name. Do this 3 more times with other names!
- */
- //To do: Insert you code below this line
- function greeting(Mom){
- console.log("Hello"+" "+ Mom);
- }
- greeting("Rosa");
- /*
- #4 Average Function
- Directions: Make a function that computes the average of two numbers.
- Example: If 6 and 10 are the parameters, the function should return 8 because (6 + 10)/2 = 8.
- Instructions:
- 1. Create a function called average with two parameters.
- 2. In the body of the function, make a return statement that calculates the average of two numbers.
- 3. Using console.log, test your function call with 6 and 10. Try it with two other numbers.
- */
- //To do: Insert you code below this line
- var x = 7;
- var y = 23;
- function average(x,y){
- console.log(x+y/2);
- }
- average(x,y);
- </script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement