Skip to content

Instantly share code, notes, and snippets.

@DennisDurairaj
Last active May 11, 2020 19:04
Show Gist options
  • Save DennisDurairaj/d58ff459f0dcdf0a695ddb35e0c404bc to your computer and use it in GitHub Desktop.
Save DennisDurairaj/d58ff459f0dcdf0a695ddb35e0c404bc to your computer and use it in GitHub Desktop.
let employeeSalary = function(initialSalary) {
var salary = initialSalary;
function changeBy(amount) {
salary += amount;
}
return {
raise: function() {
changeBy(5000);
},
lower: function() {
changeBy(-5000);
},
currentAmount: function() {
return salary;
}
};
};
let Dennis = employeeSalary(10000);
let Susan = employeeSalary(12000);
console.log(`Dennis' salary ${Dennis.currentAmount()}`); // Output: Dennis' salary 10000
console.log(`Susan's salary ${Susan.currentAmount()}`); // Output: Susan's salary 12000
Dennis.raise();
console.log(`Dennis' salary increased to ${Dennis.currentAmount()}`); // Output: Dennis' salary increased to 15000
Susan.lower();
console.log(`Susan's salary decreased to ${Susan.currentAmount()}`); // Output: Susan's salary decreased to 7000
Dennis.changeBy(); // TypeError: Dennis.changeBy is not a funciton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment