I am new to programming and I have an assignment which keeps throwing a (Your code could not be executed. Error:ReferenceError: intern is not defined
) error.
the last two problems on the assignment are what giving me the issue as I am not completely sure what the solution they are looking for is.
the instructions are Task 3: Code a 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.
and my current code looks like this
// Task 1: Code a Person class
class Person {
constructor(name = "Tom", age = 20, energy = 100) {
this.name = name;
this.age = age;
this.energy = energy;
}
doSomethingFun() {
if (this.energy > 0) {
this.energy -= 10;
console.log('Energy is decreasing, currently at:', this.energy);
} else if (this.energy == 0) {
this.sleep();
}
}
sleep() {
this.energy += 10;
console.log('Energy is increasing, currently at:', this.energy);
}
}
// Task 2: Code a Worker class
class Worker extends Person {
constructor(name, age, energy, xp = 0, hourlyWage = 10) {
super(name, age, energy);
this.xp = xp;
this.hourlyWage = hourlyWage;
}
goToWork() {
this.xp + 10;
console.log('Experience is increasing, currently at:', this.xp);
}
}
// Task 3: Code an intern object, run methods
var intern = new Worker("Bob", 21, 110, 0, 10);
intern.goToWork()
console.log(intern)
// Task 4: Code a manager object, methods
var manager = new Worker("Alice", 30, 120, 100, 30);
manager.doSomethingFun()
console.log(manager)