Skip to content

Instantly share code, notes, and snippets.

@virtualjess
Last active September 24, 2020 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save virtualjess/761d6ca9a343fe744f14a073cc875ffe to your computer and use it in GitHub Desktop.
Save virtualjess/761d6ca9a343fe744f14a073cc875ffe to your computer and use it in GitHub Desktop.
// attempt 1 of 2
// Codecademy throws the following text:
// "The generatePaycheck() function should logs(sic) to the console the hoursWorked multiplied by the hourlyWage .
// It should then set the hoursWorked to 0 ."
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;
}
set hoursWorked(hoursWorked) {
this._hoursWorked = hoursWorked
}
logHours (num) {
this._hoursWorked += num;
}
generatePaycheck() {
let payCheck = this._hoursWorked * this._hourlyWage;
return console.log(payCheck);
hoursWorked = 0;
}
};
//attempt 2; fixed the return on generatePaycheck and potential variable scoping problem with hoursWorked
// sadly it returns nothing at all, and they don't show you the solution
// or what tests you're failing, it just doesn't let you proceed with the quiz
// so I am still not sure whay it isn't working!
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;
}
set hoursWorked(workedHours) {
this._hoursWorked = workedHours;
}
logHours (num) {
this._hoursWorked += num;
}
generatePaycheck() {
let payCheck = this._hoursWorked * this._hourlyWage;
console.log(payCheck);
hoursWorked = 0;
}
};
@virtualjess
Copy link
Author

// correct answer
generatePaycheck() {
let payCheck = this.hoursWorked * this.hourlyWage; //using getters to get the values
console.log(payCheck);
this.hoursWorked = 0; //using the setter to set the value
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment