Hello i am stuck in this code ooprogramming.js

// Task 1: Code a Person class
class person {
    constructor(name = "Tom", age = 20, energy = 100) {
        this.name = name;
        this.age = age;
        this.energy = energy;
    }
    sleep() {
        this.energy += 10;
        console.log('Energy is increasing, currently at:', this.energy)
    }
    doSomethingFun() {
        this.energy -= 10;
        console.log(console.log('Energy is decreasing, currently at:', this.energy))
    }   
}

// 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 = hourlywage;
    }
    goToWork() {
        xp += 10;
        console.log('Experience points is increasing, currently at:', this.xp)
    }
}
// Task 3: Code an intern object, run methods
function intern() {
    newIntern = new Worker(0, 10, "Bob", 21, 110);
    newIntern.goToWork();
    return  NewIntern;
}
intern();

// Task 4: Code a manager object, methods
function manager() {
    newManager = new Worker(100, 30, "Alice", 30, 120);
    newManager.doSomethingFun();
    return newManager;
}
manager(); 

and give this error

 home/coder/project/learn/ooprogramming.js:32
    newIntern = new Worker(0, 10, "Bob", 21, 110);
    ^

ReferenceError: Worker is not defined
    at intern (/home/coder/project/learn/ooprogramming.js:32:5)
    at Object.<anonymous> (/home/coder/project/learn/ooprogramming.js:36:1)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    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.066 seconds

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

i write this code and it doesn’t work

i need to know where problem to solve

What is this code for?

What is it supposed to do?

What have you tried to fix it?

the code is java script
i search in google to know how to solve it

Ok. Well we aren’t here to just solve your homework for you. So please talk to us about what you have tried and what the code should do.

thank you i solve it and it is working nw

1 Like

[Running] node “/home/coder/project/learn/ooprogramming.js”

Experience points is increasing, currently at: 10

Energy is decreasing, currently at: 110

undefined

[Done] exited with code=0 in 0.075 seconds