JavaScript Methods Worksheet

Question 1

How is a method different from a regular function in JavaScript?

A method is a function that belongs to an object, while a regular function is a separate block of code that is not attach to any object.

Question 2

Why would we want to add methods to an object?

to give the object behavior

Question 3

How can we access the property of an object from inside the body of a method of that object?

You have to use the "this" keyword, followed by the dot operator, and then the name of the property that you wish to access.

Coding Problems

Coding Problems - See the 'script' tag below this h3 tag. You will have to write some JavaScript code in it.

Always test your work! Check the console log to make sure there are no errors.