Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const bankacount = (() => {
- let balance = 0;
- let addedBallance = (num) => {
- if (!isNaN(num) && num > 0 ) {
- balance = num;
- } else {
- throw 'Not enough Money'
- }
- return balance;
- };
- const deposit = (numbers) => {
- if (isNaN(numbers)) {
- throw 'Error';
- };
- balance += numbers;
- return balance;
- };
- const withdraw = (withdrawSum) => {
- if (isNaN(withdrawSum)) {
- throw 'Error'
- }
- if (balance - withdrawSum < 0) {
- throw 'not enough balance'
- }
- balance -= withdrawSum;
- return balance;
- };
- return {
- addedBallance,
- deposit,
- withdraw,
- get currentBallance() {
- return balance;
- },
- };
- })();
- bankacount.addedBallance(1000);
- bankacount.deposit(100);
- bankacount.deposit(100);
- console.log(bankacount.currentBallance);
- bankacount.withdraw(150);
- console.log(bankacount.currentBallance);
Advertisement
Add Comment
Please, Sign In to add comment