Vacation pay calculator – JS

Hi folks! I'm a bit stuck, and not really sure how to google this issue ... When running the script in this repo I get a NaN when calculating vacationPay at the end ... I understand that something is not defined, but I don't understand what that is ... https://github.com/AMarlonG/JavaScript/blob/main/Projects/calculator.js
GitHub
JavaScript/calculator.js at main · AMarlonG/JavaScript
First baby steps into JS. Contribute to AMarlonG/JavaScript development by creating an account on GitHub.
8 Replies
Chris Bolson
Chris Bolson2y ago
You have two issues here. 1. monthlyIncome is not defined any where 2. You are telling the vacationPay function to expect 5 parameters but are not sending it any. If you want to use the variables that you have defined without specifically passing them, you mustn't the function to expect them as parameters. Something like this should get you closer:
let monthlyIncome = brokenDownIncome.monthlyIncome();
let vacationPay = () => monthlyIncome + (myIncome * vacationPayPercentOfIncome) - (monthlyIncome / vacationDaysAllowedWithPay) * vacationDaysAllowed;
let monthlyIncome = brokenDownIncome.monthlyIncome();
let vacationPay = () => monthlyIncome + (myIncome * vacationPayPercentOfIncome) - (monthlyIncome / vacationDaysAllowedWithPay) * vacationDaysAllowed;
Å Marlon G
Å Marlon G2y ago
Right, so making the methods into variables will solve my problem, but I guess there are several ways of doing this, and what about this way: Would it be more readable to make the methods inside of brokenDownIncome to variables there, or will they then be locally scoped and not available outside for use in vacationPay? ... and I moved the code to this repo instead: https://github.com/AMarlonG/JS-Projects/blob/main/Taxes%20and%20benefits/calculator.js
Chris Bolson
Chris Bolson2y ago
Yes, if you make the variables within the vactionPay function they will only be available within that function.
Å Marlon G
Å Marlon G2y ago
Ah, ok. So your way then. 😇 Thanx! 👍
Chris Bolson
Chris Bolson2y ago
Just a disclaimer - "my way" is not necessarily the best and certainly not the only way. I am more about resolving the issue at hand.
Å Marlon G
Å Marlon G2y ago
... sorry. I re-read your comment ... maybe I was unclear, but did you mean brokenDownIncome instead of vacationPay ... brokenDownIncome is the object holding the break down methods of income ... I hope.
Chris Bolson
Chris Bolson2y ago
sorry, I also miss-read your comment I don't think that making the variables within brokenDownIncome is an option
Å Marlon G
Å Marlon G2y ago
So making the method into a property doesn't work, or is bad code writing?
const brokenDownIncome = {
monthly: monthlyIncome() {
return noDecimals(myIncome / months);
},
};
const brokenDownIncome = {
monthly: monthlyIncome() {
return noDecimals(myIncome / months);
},
};
Want results from more Discord servers?
Add your server