Code Editor

The calculator program should be able to perform a math operation on a number. We should be able to give a calculator a number, have it perform a task on it like multiplication, then print a result.

Currently, we have no way to give a function a number. To do this, we can use parameters. Parameters are variables that we can set when we call the function. For example:

function multiplyByThirteen(inputNumber) { console.log(inputNumber * 13); } multiplyByThirteen(9); // Output: 117
  1. We added inputNumber within the parentheses of the multiplyByThirteen function. inputNumber is a parameter.
  2. Inside the multiplyByThirteen function, we use console.log to print the inputNumber by 13.
  3. When we call the multiplyByThirteen function on the last lines, we set the inputNumber parameter. For instance, multiplyByThirteen(9) calls the multiplyByThirteen function, and sets inputNumber as 9. Then, inside the block of the multiplyByThirteen function, 9 is multiplied by 13, resulting in 117 printing to the console.
  4. Note on terminology: inputNumber is a parameter, but when we call multiplyByThirteen(9), the 9 is called an argument. Therefore, arguments are provided when you call a function, and parameters receive arguments as their value. So, inputNumber is a parameter and its value is the argument 9, since we wrote multiplyByThirteen(9).

Parameters let us write logic inside functions that can be modified based on when we call the function, which will help make our functions more flexible.

Report a Bug
If you see a bug or any other issue with this page, please report it here.