- View -> Editor Layout -> Two Columns
- To view this file in Preview mode, right click on this README.md file and
Open Preview
- Select your code file in the code tree, which will open it up in a new VSCode tab.
- Drag your assessment code files over to the second column.
- Great work! You can now see instructions and code at the same time.
- Questions about using VSCode? Please see our support resources here:
Visual Studio Code on Coursera
- Select your JavaScript file
- Select the "Run Code" button in the upper right hand toolbar of VSCode.
Ex: It looks like a triangular "Play" button.
Code a Person class, with three parameters in the constructor: name, age, and energy.
Set the default parameters in the Person class as follows:
name = "Tom"
age = 20
energy = 100
Code two methods in the Person
class. Name those methods sleep()
and doSomethingFun()
.
The sleep()
method should take the existing energy level and increase it by 10.
The doSomethingFun() method should take the existing energy level and decrease it by 10.
Code a sub-class, inheriting from the Person
class, and name it Worker
.
The Worker
class has two additional parameters in the constructor:
- xp (for "experience points")
- hourlyWage.
These properties are set to the following default values:
xp = 0
hourlyWage = 10
The Worker
class has all the paramerters and methods of its super-class.
Additionally, it has the goToWork()
method, which, whenever it's run, increases the value of the xp
property by 10.
Inside the intern function instantiate the Worker
class to code a new intern object.
The intern should have the following characteristics:
name: Bob
age: 21
energy: 110
xp: 0
hourlyWage: 10
Run the goToWork()
method on the intern object. Then return
the intern object.
Inside the manager function instantiate the Worker
class to code a new manager
object.
The manager object should have the following characteristics:
name: Alice
age: 30
energy: 120
xp: 100
hourlyWage: 30
Run the doSomethingFun()
method on the manager object. Then return
the manager object.