Instead of giving those instructions for every hamburger, we can group and name them as a single function:

function makeHamburger() {
  Add bread
  Add burger patty
  Add pickles
  Add bread

A function is a named sequence of instructions, packaged as a unit, that performs a specific task.

We’ve defined the function by giving it instructions and a name, but how do we use it? We use a function by calling it. When we call makeHamburger() we expect all of its steps to be executed.


Build hamburgers with a function: In this example you can call the function by clicking the makeHamburger() button. Make three hamburgers by calling the function three times.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?