DEV Community

Discussion on: Avoid use IF on our JS scripts

Collapse
 
gameoverwill profile image
Wilfredo Pérez

Hey Damian the last example is not working.

//Create function to different behaviour, same parameter call.
const qaSalary  = (base) => base+9000*0.10;
const devSalary = (base) => base+1000*0.60;

//Add function to the object.
const bob = {
  name:'Bob',
  salary:1000,
  job_type:'DEVELOPER',
  calc: devSalary
};

const mary = {
  name:'Mary',
  salary:1000,
  job_type:'QA',
  calc: qaSalary
};

//Same call.
console.log('Salary',bob.calc());
console.log('Salary',mary.calc());

the output is:

Salary NaN
Salary NaN
Collapse
 
damxipo profile image
Damian Cipolat

:o :O yes that true, I will fix it. thanks for tell me.