Functions Revisited

We can write our own functions!

Creating Functions

How do we write our own functions?

  1. start with the keyword, function
  2. followed by the name of your function
  3. followed by parentheses
  4. followed by an optional list of comma separated parameters (input)
  5. close parentheses
  6. a block of code between curly braces

An Example

function foo() {
	console.log("FOO!");
}

A Function With Parameters (Input)

How do we create a function that has parameters or inputs?

function foo(s) {
	console.log(s + "!");
}

Giving Back Values (Output)

How do we create a function that gives back values?

// use the keyword, return
function foo(s) {
	return s + "!";
}
console.log(foo("hi"));

A Few Notes About Functions

A Function is Another Type!

Demos