Created
August 11, 2019 13:13
-
-
Save pcast01/c94a9b59177784c50b41e336d4173a08 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
var dwightSalary = (function() { | |
var salary = 60000; | |
function changeBy(amount) { | |
salary += amount; | |
} | |
return { | |
raise: function() { | |
changeBy(5000); | |
}, | |
lower: function() { | |
changeBy(-5000); | |
}, | |
currentAmount: function() { | |
return salary; | |
} | |
}; | |
})(); | |
alert(dwightSalary.currentAmount()); // $60,000 | |
dwightSalary.raise(); | |
alert(dwightSalary.currentAmount()); // $65,000 | |
dwightSalary.lower(); | |
dwightSalary.lower(); | |
alert(dwightSalary.currentAmount()); // $55,000 | |
dwightSalary.changeBy(10000) // TypeError: undefined is not a function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment