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, 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 up