Adding a Property Solution1:16 with Ashley Boucher
Solution video for adding a property on the fly code challenge.
For this previous challenge, 0:00 you were to add a property to the object literal on the fly. 0:01 This property is characters, and it's set to the number of characters in the string. 0:04 Outside of the object literal you can add a new property to it by 0:10 accessing the new property with dot or bracket notation and giving it a value. 0:13 This process is a lot like creating a new variable. 0:18 myString.characters indicates that now there is going to be a new property on 0:22 myString called characters. 0:26 Then we assign it a value, just like you do when you declare a variable. 0:28 Now, strings, like arrays, come with a property called length. 0:33 On a string, the length property returns the number of characters. 0:37 We'll access the length property on the string property of the myString object. 0:41 Great work. 0:51 We can test this out by logging the value of the characters property to the console. 0:52 Now I'll save and jump down to the terminal. 1:02 Looks great, there are 34 characters in this phrase. 1:10 Don't worry, I counted. 1:13
You need to sign up for Treehouse in order to download course files.Sign up