I feel like I could fix this if I understood how to read the output log. Here is what I am trying to do:
Task 1: Code a Person class
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 exisiting energy level and increase it by 10.
The doSomethingFun() method should take the exisiting energy level and decrease it by 10.
Task 2: Code a Worker class
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 parameters 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.
Task 3: Code an intern object
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.
Task 4: Code a manager 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.
Here is my code:
// Task 1: Code a Person class
class Person {
constructor(name = Tom, age = 20, engergy = 100) {
this.name = name;
this.age = age;
this.energy = energy;
}
sleep() {
this.energy += 10
}
doSomethingFun() { this.energy -= 10 }
}
// Task 2: Code a Worker class
class Worker extends Person {
constructor(xp = 0, hourlyWage = 10, name, age, energy) {
super(name, age, energy);
this.xp = xp;
this.hourlyWage = this.hourlyWage;
}
goToWork() { this.exp += 10 }
}
// Task 3: Code an intern object, run methods
function intern() {
{
var intern = new worker(0, 10, Bob, 21, 110)
intern.goToWork();
return intern;
}
}
// Task 4: Code a manager object, methods
function manager() {
var manager = new Worker(100, 30, Alice, 30, 110);
manager.doSomethingFun();
}
Here is the OUTPUT in Visual Basic:
[Running] node “/home/coder/project/learn/tempCodeRunnerFile.js”
/home/coder/project/learn/tempCodeRunnerFile.js:2
(name, age, energy);
SyntaxError: Unexpected end of input
at wrapSafe (internal/modules/cjs/loader.js:1001:16)
at Module._compile (internal/modules/cjs/loader.js:1049:27)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
at internal/main/run_main_module.js:17:47
[Done] exited with code=1 in 0.067 seconds
[Running] node “/home/coder/project/learn/ooprogramming.js”
[Done] exited with code=0 in 0.065 seconds
Help please.