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.jsGitHub
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
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:
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.jsYes, if you make the variables within the vactionPay function they will only be available within that function.
Ah, ok. So your way then. 😇
Thanx!
👍
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.
... 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.sorry, I also miss-read your comment
I don't think that making the variables within brokenDownIncome is an option
So making the method into a property doesn't work, or is bad code writing?