Zhorzh

Untitled

Jan 20th, 2022
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. const bankacount = (() => {
  2. let balance = 0;
  3. let addedBallance = (num) => {
  4. if (!isNaN(num) && num > 0 ) {
  5. balance = num;
  6. } else {
  7. throw 'Not enough Money'
  8. }
  9. return balance;
  10. };
  11. const deposit = (numbers) => {
  12. if (isNaN(numbers)) {
  13. throw 'Error';
  14. };
  15. balance += numbers;
  16. return balance;
  17. };
  18. const withdraw = (withdrawSum) => {
  19. if (isNaN(withdrawSum)) {
  20. throw 'Error'
  21. }
  22. if (balance - withdrawSum < 0) {
  23. throw 'not enough balance'
  24. }
  25. balance -= withdrawSum;
  26. return balance;
  27. };
  28. return {
  29. addedBallance,
  30. deposit,
  31. withdraw,
  32. get currentBallance() {
  33. return balance;
  34. },
  35. };
  36. })();
  37. bankacount.addedBallance(1000);
  38. bankacount.deposit(100);
  39. bankacount.deposit(100);
  40. console.log(bankacount.currentBallance);
  41. bankacount.withdraw(150);
  42. console.log(bankacount.currentBallance);
Advertisement
Add Comment
Please, Sign In to add comment