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- 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
6
- Complete the function in exercise2.js so that it triples the input
36