Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Calling a Method Solution1:04 with Ashley Boucher
Solution video for calling a method code challenge.
Now that you've added a method to the object literal,
your task was to practice calling this method.
After the object, you were asked to create a variable and
set it to the return value from the countWords method.
Let's declare the variable.
I'll call it numWords, but any variable name would work.
Now, if you recall, to access a property on an object or to call one of its methods
using dot notation, you write the name of the object, which in our case is myString,
because that's the variable that the object is stored in,
followed by a dot, followed by the name of the property or method.
Dot notation isn't the only way to access an object's properties or methods,
you can also use bracket notation.
So I'll edit the code to show you how to do this with bracket notation, too.
Both dot and bracket notation are acceptable to use when working with
objects, but I find dot notation easier to read and write.
You need to sign up for Treehouse in order to download course files.Sign up