“Work Around” project


#1

Hi there!
I got a syntax error after doing “Work Around” project, on Modules (Mod. 8)
Code of both importing and exporting files below. Help please!

// **exporting 'employee.js file code:**

let Employee = {
  salary: 100000;
};

export 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 }
};

export function getCadre() {
  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';
}

export function calculateTax() {
  return payGrades[getCadre()].taxMultiplier * Employee.salary;
}

export function getBenefits() {
  return payGrades[getCadre()].benefits.join(', ');
}

export function calculateBonus() {
  return .02 * Employee.salary;
}

export function reimbursementEligibility() {
  let reimbursementCosts = { health: 5000, housing: 8000, wellness: 6000, gym: 12000 };
  let totalBenefitsValue = 0; 
  let employeeBenefits = payGrades[getCadre()].benefits;
  for (let i = 0; i < employeeBenefits.length; i++) {
    totalBenefitsValue += reimbursementCosts[employeeBenefits[i]];
  }
  return totalBenefitsValue;
}

export default Employee;

// **importing 'workAround.js file code:**

import {getcadre, calculateTax, getBenefits, calculateBonus, reimbursementEligibility } from './employee';
import Employee from './employee';

function getEmployeeInformation(inputSalary) {
  Employee.salary = salary;
  console.log('Cadre: ' + getCadre());
  console.log('Tax: ' + calculateTax());
  console.log('Benefits: ' + getBenefits());
  console.log('Bonus: ' + calculateBonus());
  console.log('Reimbursement Eligibility: ' + reimbursementEligibility() + '\n');
}

getEmployeeInformation(10000);
getEmployeeInformation(50000);
getEmployeeInformation(100000);

#2

What does the error message read?


#3

If you are on step 8, then that line should read,

Employee.salary = inputSalary;

There are three instances of this expression that we also need to set to Employee.

payGrades[Employee.getCadre()]

I’m justing moving on to step 10.

Okay, finished the project with no syntax errors but can use my code to compare to your latest.


#4

After making all changes, I still get errors. See revised code and error bellow:

// exporting file:

let salary = 10000;

let Employee = {
salary: 10000;
};
export 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 }
};

export function getCadre() {
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’;
}

export function calculateTax() {
return payGrades[Employee.getCadre()].taxMultiplier * Employee.salary;
}

export function getBenefits() {
return payGrades[Employee.getCadre()].benefits.join(’, ');
}

export function calculateBonus() {
return .02 * Employee.salary;
}

export function reimbursementEligibility() {
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;

// Importing file:

import {getcadre, calculateTax, getBenefits, calculateBonus, reimbursementEligibility } from ‘./employee’;
import Employee from ‘./employee’;

function getEmployeeInformation(inputSalary) {
Employee.salary = inputSalary;
console.log('Cadre: ’ + getCadre());
console.log('Tax: ’ + calculateTax());
console.log('Benefits: ’ + getBenefits());
console.log('Bonus: ’ + calculateBonus());
console.log('Reimbursement Eligibility: ’ + reimbursementEligibility() + ‘\n’);
}

getEmployeeInformation(10000);
getEmployeeInformation(50000);
getEmployeeInformation(100000);

// Error:

/home/ccuser/node_modules/babel-core/lib/transformation/file/index.js:558
throw err;
^

SyntaxError: /home/ccuser/workspace/intermediate-javascript_modules-workAround/employee.js: Unexpected token, expected , (5:15)
3 |
4 | let Employee = {

5 | salary: 10000;
| ^
6 | };
7 | //Employee.salary = 10000; <- means same as object above.
8 |
at Parser.pp$5.raise (/home/ccuser/node_modules/babylon/lib/index.js:4454:13)
at Parser.pp.unexpected (/home/ccuser/node_modules/babylon/lib/index.js:1761:8)
at Parser.pp.expect (/home/ccuser/node_modules/babylon/lib/index.js:1749:33)
at Parser.pp$3.parseObj (/home/ccuser/node_modules/babylon/lib/index.js:3978:12)
at Parser.pp$3.parseExprAtom (/home/ccuser/node_modules/babylon/lib/index.js:3719:19)
at Parser.parseExprAtom (/home/ccuser/node_modules/babylon/lib/index.js:7238:22)
at Parser.pp$3.parseExprSubscripts (/home/ccuser/node_modules/babylon/lib/index.js:3494:19)
at Parser.pp$3.parseMaybeUnary (/home/ccuser/node_modules/babylon/lib/index.js:3474:19)
at Parser.pp$3.parseExprOps (/home/ccuser/node_modules/babylon/lib/index.js:3404:19)
at Parser.pp$3.parseMaybeConditional (/home/ccuser/node_modules/babylon/lib/index.js:3381:19)


#5

The unexpected token is the semi-colon which does not belong inside an object.


#6

The video shows otherwise (with semi-colon). Anyway I removed it, and kept getting another error cause by “Employee.” prepended to “getCadre”. I do not recall instructions in the exercise to remove it. But the code is finally all set:

let salary = 10000;

let Employee = {
salary: 10000
};
//Employee.salary = 10000; <- means same as object above.

export 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 }
};

export function getCadre() {
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’;
}

export function calculateTax() {
return payGrades[getCadre()].taxMultiplier * Employee.salary;
}

export function getBenefits() {
return payGrades[getCadre()].benefits.join(’, ');
}

export function calculateBonus() {
return .02 * Employee.salary;
}

export function reimbursementEligibility() {
let reimbursementCosts = { health: 5000, housing: 8000, wellness: 6000, gym: 12000 };
let totalBenefitsValue = 0;
let employeeBenefits = payGrades[getCadre()].benefits;
for (let i = 0; i < employeeBenefits.length; i++) {
totalBenefitsValue += reimbursementCosts[employeeBenefits[i]];
}
return totalBenefitsValue;
}

export default Employee;

import {getCadre, calculateTax, getBenefits, calculateBonus, reimbursementEligibility } from ‘./employee’;
import Employee from ‘./employee’;

function getEmployeeInformation(inputSalary) {
Employee.salary = inputSalary;
console.log('Cadre: ’ + getCadre());
console.log('Tax: ’ + calculateTax());
console.log('Benefits: ’ + getBenefits());
console.log('Bonus: ’ + calculateBonus());
console.log('Reimbursement Eligibility: ’ + reimbursementEligibility() + ‘\n’);
}

getEmployeeInformation(10000);
getEmployeeInformation(50000);
getEmployeeInformation(100000);


#7

As I recall, the change to remove Employee. from getCadre was around step 14ish.

Are you getting three sets of output?


#8

Yes, I finally got same output as the video. My many thanks to you!