the project link is hereWorkAround
from step 1 to step 9, we modify the employee.js and export default Employee, but we did not change payGrade into Employee’s property. Does that mean that this payGrade is not exported?
if this payGrade is not exported, how would workAround.js run successfully? actually it did run successfully.
this is the employee.js code:
let Employee = {
salary: 100000
};
let payGrades = {
entryLevel: { taxMultiplier: .05, benefits: [‘health’], minSalary: 10000, maxSalary: 49999 },
midLevel: { taxMultiplier: .1, benefits: [‘health’, ‘housing’], minSalary: 50000, maxSalary: 99999 },
seniorLevel: { taxMultiplier: .2, benefits: [‘health’, ‘housing’, ‘wellness’, ‘gym’], minSalary: 100000, maxSalary: 200000 }
};
Employee.getCadre = function(){
if (Employee.salary >= payGrades.entryLevel.minSalary && Employee.salary <= payGrades.entryLevel.maxSalary) {
return ‘entryLevel’;
} else if (Employee.salary >= payGrades.midLevel.minSalary && Employee.salary <= payGrades.midLevel.maxSalary) {
return ‘midLevel’;
} else return ‘seniorLevel’;
};
Employee.calculateTax = function(){
return payGrades[Employee.getCadre()].taxMultiplier * Employee.salary;
};
Employee.getBenefits = function() {
return payGrades[Employee.getCadre()].benefits.join(’, ');
};
Employee.calculateBonus = function() {
return .02 * Employee.salary;
};
Employee.reimbursementEligibility = function() {
let reimbursementCosts = { health: 5000, housing: 8000, wellness: 6000, gym: 12000 };
let totalBenefitsValue = 0;
let employeeBenefits = payGrades[Employee.getCadre()].benefits;
for (let i = 0; i < employeeBenefits.length; i++) {
totalBenefitsValue += reimbursementCosts[employeeBenefits[i]];
}
return totalBenefitsValue;
};
export default Employee;
and this is the workAround.js code:
import Employee from ‘./employee’;
function getEmployeeInformation(inputSalary) {
Employee.salary = inputSalary;
console.log('Cadre: ’ + Employee.getCadre());
console.log('Tax: ’ + Employee.calculateTax());
console.log('Benefits: ’ + Employee.getBenefits());
console.log('Bonus: ’ + Employee.calculateBonus());
console.log('Reimbursement Eligibility: ’ + Employee.reimbursementEligibility() + ‘\n’);
};
getEmployeeInformation(10000);
getEmployeeInformation(50000);
getEmployeeInformation(100000);
and work out good. this is the result:
Cadre: entryLevel
Tax: 500
Benefits: health
Bonus: 200
Reimbursement Eligibility: 5000
Cadre: midLevel
Tax: 5000
Benefits: health, housing
Bonus: 1000
Reimbursement Eligibility: 13000
Cadre: seniorLevel
Tax: 20000
Benefits: health, housing, wellness, gym
Bonus: 2000
Reimbursement Eligibility: 31000
I think the payGrades object is not exported, how does it work? If the payGrade exported successfully, but we did not add any ‘Emlpoyee.’ before payGrade, I am confused.