Skip to content

Latest commit

 

History

History
42 lines (28 loc) · 764 Bytes

File metadata and controls

42 lines (28 loc) · 764 Bytes

Functions are blocks of code that can do a task as many times as you ask it to. They take an input and return an output.

Here's a function that doubles a number:

function double(number) {
  return number * 2;
}

To use the function we need to: a) call it with an input and b) assign the returned value to a variable

var result = double(2);

console.log(result); // 4

Exercise

  • Complete the function in exercise.js so that it halves the input
  • Try calling the function more than once with some different numbers

Remember to use the return keyword to get a value out of the function

Expected result

6

Exercise 2

  • Complete the function in exercise2.js so that it triples the input

Expected result

36