"Introduction to HTML and CSS (2016)" was retired on July 31, 2024. You are now viewing the recommended replacement.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Practice Object Basics in JavaScript!
You have completed Practice Object Basics in JavaScript!
Preview
Solution video for calling a method code challenge.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Now that you've added a method
to the object literal,
0:00
your task was to practice
calling this method.
0:02
After the object,
you were asked to create a variable and
0:05
set it to the return value
from the countWords method.
0:08
Let's declare the variable.
0:11
I'll call it numWords, but
any variable name would work.
0:13
Now, if you recall, to access a property
on an object or to call one of its methods
0:20
using dot notation, you write the name of
the object, which in our case is myString,
0:24
because that's the variable
that the object is stored in,
0:29
followed by a dot, followed by
the name of the property or method.
0:32
Dot notation isn't the only way to access
an object's properties or methods,
0:39
you can also use bracket notation.
0:43
So I'll edit the code to show you how
to do this with bracket notation, too.
0:46
Both dot and bracket notation
are acceptable to use when working with
0:56
objects, but I find dot notation
easier to read and write.
1:00
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up