Please I need help with this JavaScript question

Define a class named Employee .

Your class should have a constructor function that takes in an employee’s name and hourlyWage and sets them as properties with those names. An hoursWorked property should be initialized to 0 .

The Employee class should have a logHours() function that takes in a number of hours worked and increments the hoursWorked property by that amount.

The Employee class should have a generatePaycheck() function that logs to the console the hoursWorked multiplied by the hourlyWage . It should then set the hoursWorked to 0 .

// Define your class below:
class Employee{
constructor(name, hourlyWage){
this._name = name;
this._hourlyWage = hourlyWage;
this._hoursWorked = 0;
}
get name(){
return this._name;
}

get hourlyWage(){
return this._hourlyWage;
}

get hoursWorked(){
return this._hoursWorked;
}

logHours(hours){
hoursworked += hours;
}

generatePaycheck(){
console.log(this._hoursWorked * this._hourlyWage);

}

set hoursWorked(value){
this._hoursWorked = value;
}

}
const Tare = new Employee(‘Efe’, 20, 5)
console.log(Tare._hoursWorked)
console.log(Tare._name)
Tare.generatePaycheck();
I feel there is something wrong with the hours worked , I do not know how to fix it.

1 Like

class Employee {
constructor(name, hourlyWage) {
this._name = name;
this._hourlyWage = hourlyWage;
this._hoursWorked = 0;
}

get name() {
return this._name;
}

get hourlyWage() {
return this._hourlyWage;
}

get hoursWorked() {
return this._hoursWorked;
}

logHours(hours) {
this._hoursWorked += hours;
}

generatePaycheck() {
console.log(this._hoursWorked * this._hourlyWage);
this._hoursWorked = 0;
}
}

I submitted this and worked. You need to reset the hours worked inside the generatePaycheck() method.