- Open your command line and navigate to your
repos
directory (if you do not have arepos
folder, then you can usemkdir repos
to create one) - Use this template repository to start a new project in your repos folder:
git clone <repo_name>
- cd
repo_name
to navigate into your new repo directory - Start Visual Studio Code and select 'Open Folder'. Then select
repo_name
to open the folder in the editor (or just typecode .
in your terminal inside the repo directory) - Follow the instructions on the README.md file to complete exercises
- Open the app.js file to get started
- Expanding from our exercise example during the lesson, create a parent class
class Person {}
with properties forname
,pets
,residence
, andhobbies
. The Person class will also have a methodinfo()
andsoundOff()
.
- Use class notation to create a class named
Person
- Declare the
constructor()
method with parametersname
(string),pets
(number),residence
(string), andhobbies
(array) allowed to be passed in - The
constructor()
method assignsthis.
properties to each parameter - Declare an
info()
method on the class thatconsole.log
's a string giving information about the Person object- You should display the
name
, number ofpets
,residence
, and each hobby from thehobbies
array
- You should display the
- Declare a
greeting()
method thatconsole.log
's the sound of an Person... ex:greeting() {console.log("Hello fellow person!")}
Now we'll create a subclass Coder
that inherits from our Person
class
- Use class notation to create a class named
Coder
that inherits from thePerson
class - Declare the
constructor()
method with parametersname
(string),pets
(number),residence
(string), andhobbies
(array) allowed to be passed in - Call the
super()
method inside theconstructor
method and pass in the given parameters - Still inside the
constructor
body, assignthis.occupation
to "Full Stack Web Developer" - Override the
greeting()
method toconsole.log
a custom greeting from a coder...
Finally, let's create instances of our classes
- Create a variable and assign a Person object to it using the
new
keyword followed by the classconstructor
- Create a variable and assign a Coder object to it using the
new
keyword followed by the classconstructor
- Call the object methods and
console.log
the object properties to test your work
- Refactor the
greeting()
methods to accept aname
parameter and uses in to personalize the greeting output - Now when you call the
coder.greeting()
orperson.greeting()
methods, you can pass in thename
property from an instantiatedPerson
orCoder
object