Learn
Method Calls and Input
Introduction to Methods

Imagine making a hamburger:

  1. Place the bread down
  2. Add the burger patty
  3. Add the pickles
  4. Place the bread on top

What if you had to say each step every time you ordered a hamburger? It’s tedious. It takes a long time. (How do you fit that on a menu?) And it risks making mistakes.

In this lesson you will learn a solution to that problem: methods. A method is a reusable set of instructions that perform a specific task. Developers use methods to make their code organized, maintainable, and repeatable.

You might hear methods also called functions — for now, the difference isn’t important to us.

By the end of this lesson you will be able to recognize methods, call them with multiple arguments, capture their returned values, and define a basic method.

Instructions

  1. First make two burgers without methods: add bread, patty, pickles, and bread.
  2. Then make two burgers with the method makeHamburger()
  3. Which way is faster? Which is more prone to mistakes?
Folder Icon

Take this course for free

Already have an account?