Social Icons

Pages

Thursday, December 1, 2016

Introduction to Objects I 13/33

Function Review
In this lesson we are going to focus onmethods. 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 functionkeyword followed by:
A pair of parentheses ( ) with optional parameters inside.
A pair of curly braces with the function's code inside { }.
A semicolon ;.
And when we call the function, we can put inputs (arguments) for the parameters.
For example, the square function on line 2takes x as its parameter and returns that parameter squared.


Instructions
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.
// Accepts a number x as input and returns its square
var square = function (x) {
  return x * x;
};
// Write the function multiply below
// It should take two parameters and return the product
var multiply = function (x) {
  return x * y;
};

No comments:

Post a Comment