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