Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Solution video for adding a property on the fly 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
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 upYou need to sign up for Treehouse in order to set up Workspace
Sign up