Somebody help me please!

I get a challenge to build OOP in javascript, and i don’t know how to do with method in classes part, This is the task that i working on :

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 existing energy level and increase it by 10.

The doSomethingFun() method should take the existing energy level and decrease it by 10.

and this is my code so far :

// Task 1: Code a Person class
class Person{
    constructor(name,age,energy) {
        this.name = name;
        this.age = age;
        this.energy = energy;
    }
    sleep() {
        
    }
    doSomethingfun() {
        
    }
}

Hi again.
I would suggest you to go through OOP part of the JS course here.

It covers the basic stuff about such matters. There is all knowledge you need for this and even more.

1 Like

Hi Stephen, we do not appreciate sharing solutions here because it doesn’t allow anyone to learn from working out bugs themselves.