Skip to content

Instantly share code, notes, and snippets.

@RCTumolac
Last active February 8, 2017 23:07
Show Gist options
  • Save RCTumolac/918e00998d4d132745dae6f9731a9e25 to your computer and use it in GitHub Desktop.
Save RCTumolac/918e00998d4d132745dae6f9731a9e25 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=918e00998d4d132745dae6f9731a9e25
<!DOCTYPE html>
<html>
<head>
<title>Four Functions</title>
</head>
<body>
<!-- Put your page markup here -->
<h1 id = "1"></h1>
<h1 id = "2"></h1>
<h1 id = "3"></h1>
<h1 id = "4"></h1>
</body>
</html>
{"enabledLibraries":["jquery"]}
/*
#1
Cubed
Directions: Make a program that returns the cubed value of the parameter. Ex: 2 --> 8
Instructions:
1. Declare a function called cubed.
2. Give the function a parameter named num.
2b. Call the function with 2 as the parameter
3. In the body of the function, make a return statement that multiplies the parameter by itself 3 times.
4. console.log the function call
*/
//To do: Insert you code below this line
function cubed(x){
x = x*x*x;
$("#1").append(x);
}
console.log(cubed(2));
/*
#2
So Last Year Function
Directions: Make a program that tells you the grade and age you were last year
Instructions:
1. Declare a function called lastYear.
2. Give the function a parameter named year.
2b. Call the function with 2015 as the first parameter
3. In the body of the function, make a return statement that subtracts one from the parameter.
4. Create two console.log statements.
4a. one statement should print the grade you were in last year
4b. one statement should print the age you were in last year
*/
//To do: Insert you code below this line
function lastYear(year){
year -= 1;
$("#2").append("In " + year + " you made an A and you were 14 years old.");
}
console.log(lastYear(2015));
/*
#3
Hello Name
Directions: Make a program that says hello to 3 different people.
Instructions:
1. Declare a function called greeting.
2. Give the function a parameter named person.
2b. Call the function with your name as a string.
3. In the body of the function, make a return statement with the string hello added to the parameter.
4. Create three console.log statements with a function call of the names of people from around the room.
*/
//To do: Insert you code below this line
function greeting(person){
$("#3").append("Hello, " + person + "! ");
}
console.log(greeting("Adam"));
console.log(greeting("Dave"));
console.log(greeting("Bob"));
/*
#4
Directions: Make a function that computes the average of two numbers
Instructions:
1. Create a function called average with two parameters, x and y
2. Return the sum of x and y divded by 2
Test your function with console.log on 2 sets of inputs (numbers).
*/
//To do: Insert you code below this line
function average(x, y){
x = x+y;
$("#4").append(x/2);
}
console.log(average(2, 3));
//console.log(average(3, 4));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment