Introduction to Objects I
Function Review

In this lesson we are going to focus on methods. Methods are an important part of object oriented programming (OOP). OOP is an important part of programming which we'll dive into later.

Methods are similar to functions. To prepare for methods, let's do a quick refresher on functions.
Functions are defined using the function keyword followed by:

  1. A pair of parentheses ( ) with optional parameters inside.
  2. A pair of curly braces with the function's code inside { }.
  3. A semicolon ;.

And when we call the function, we can put inputs (arguments) for the parameters.

For example, the square function on line 2 takes x as its parameter and returns that parameter squared.


Define the function multiply. It should take two parameters, x and y, and return the product.

Then call your function, passing in any two arguments.

Stuck? Get a hint! Hint
Get live, fast support from Codecademy Advisors when you get stuck. Learn more.

Use square as a guide to write multiply. This time, you will have two parameters, and these should be separated by a comma inside the function's parentheses.

To call the function, just type the name of the function, followed by the arguments you want to pass. For example, if we wanted to call square, we would use square(2);