Can anyone help me please ? I'm stuck when build OOP in Javascript

function intern() {
    intern = new Worker(0, 10, "Bob", 21, 110);
    return intern;
}

intern()

//console.log(intern)

intern.goToWork()



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

manager.doSomethingFun()

i tried your direction but still didn’t pass the challenge

ok, try to go back to the prevoius version

instead of line above try

two lines:

intern.goTowork();
return intern;

I don’t know, mess around it more
I don’t even know where you are testing and trying to submit it, but I am experimneting with stuff
Do the same, and console.log stuff, and google bunch of stuff

again it’s still didn’t pass :disappointed_relieved:
even though tried this :

function intern() {
    intern = new Worker(0, 10, "Bob", 21, 110);
    intern.goToWork();
    return intern;
}
intern();


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

i think i found something weird when i tried to change variable of the function

and what was the problem?

Finally i passed this challenge :laughing: :rofl:

I changed the variable with different name…
so, before we just named it same as function name like this :

// Task 3: Code an intern object, run methods
function intern() {
    intern = new Worker(0, 10, "Bob", 21, 110);
    intern.goToWork();
    return intern;
}
intern();


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

and i changed to this :

// 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();

Bro, please give the full code.

Hey!

Please create your own topic when you have specific questions about your own challenge code. Only respond to another thread when you want to provide help to the original poster of the other thread or have follow up questions concerning other replies given to the original poster.

The easiest way to create a topic for help with your own solution is to click the Ask for Help button located on each challenge. This will automatically import your code in a readable format and pull in the challenge url while still allowing you to ask any question about the challenge or your code.

Thank you.

1 Like

if i give the full code, you will never be able to solve and increase your knowledge

Good evening freeCodeCamp please I am learning a programming with my account on your platform but I dectect that each time l attempt any test given ,it has not been marked in order to pass me to the next level, pls help me see to this my account I want to complete my unfinished course

Please create your own topic when you have specific questions about your own challenge code. Only respond to another thread when you want to provide help to the original poster of the other thread or have follow up questions concerning other replies given to the original poster.

The easiest way to create a topic for help with your own solution is to click the Ask for Help button located on each challenge. This will automatically import your code in a readable format and pull in the challenge url while still allowing you to ask any question about the challenge or your code.

Thank you.

if someone else needs a complete solution to this task, then here it is`

class Person {
constructor(name = “Tom”, age = 20, energy = 100) {
this.name = name;
this.age = age;
this.energy = energy;
}
sleep() {
this.energy += 10;
}
doSumethingFun() {
this.energy -= 10;
}
}
class Worker extends Person {
constructor(xp = 0, hourlyWage = 10, age, name, energy) {
super(name, age, energy);
this.xp = xp;
this.hourlyWage = hourlyWage;
}
sleep() {
this.energy += 10;
}
doSumethingFun() {
this.energy -= 10;
}
goToWork() {
this.xp += 10;
}
}
function intern() {
intern = new Worker(0, 10, 21, “Bob”, 110)
intern.goToWork()
return intern;
}
function manager() {
manager = new Worker(100, 30, 30, “Alice”, 120)
manager.doSumethingFun();
return manager;
}

// 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('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() {
            this.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();

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').