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
Tackle an OOP vocabulary challenge to test your skills.
Challenge Steps
- I want you to create a class called Treehouse.
- Add a class attribute called product that is equal to the string βcoding coursesβ
- Add an initializer method that takes a parameter called name.
- Add a name instance attribute set equal to the parameter being passed in.
- Create a method called learn. Inside the method return a string that contains the name instance attribute so you would get something like βTim is learning to code!β where Tim is the name passed into the class.
- Create an instance of the class and save it to a variable named my_treehouse. Pass in your name as the name parameter.
- (and final step) Call your learn method and print out the result.
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
[MUSIC]
0:00
Hi my name is Megan and
I'm a teacher here at Treehouse.
0:09
In this practice session I'm going to
test your knowledge of OOP vocabulary.
0:13
I'm sure you realize pretty quickly that
learning OOP comes with a large new set of
0:18
vocabulary words.
0:23
I'm going to give you a file with some
prompts using OOP vocabulary to test your
0:25
knowledge.
0:29
The file can be found in
the attached workspace,
0:31
or in the downloads tab below this video,
if you wanna work locally.
0:34
I also listed the instructions in the
Teacher's Notes just in case you need them.
0:38
Ready for the challenge?
0:43
First, I want you to create
a class called Treehouse.
0:47
Second, add a class attribute
called product that is
0:51
equal to the string coding courses.
0:56
Third, add an initializer method
that takes a parameter called name.
1:00
Fourth, add a name instance attribute set
equal to the parameter being passed in.
1:07
Fifth, create a method called learn.
1:15
Inside the method, return a string that
contains the name instance attribute,
1:19
so you would get something like,
Tim is learning to code,
1:25
where Tim is the name
passed into the class.
1:30
Sixth, create an instance of the class and
save it to a variable named my_treehouse.
1:35
Pass in your name as the name parameter.
1:42
Seventh and final step, call your
learn method and print out the result.
1:45
When you run the file, No
1:52
errors should be encountered and
the phrase, Megan is learning to code,
1:57
should be printed to the console where
Megan is your name that you passed in.
2:02
Good luck.
2:08
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