-
-
Save virtualjess/761d6ca9a343fe744f14a073cc875ffe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} | |
}; |
// 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
Differences between properties and methods (including setters/getters)