Last active
May 11, 2020 19:04
-
-
Save DennisDurairaj/d58ff459f0dcdf0a695ddb35e0c404bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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