momo3141

bank

Jan 19th, 2023
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const bankAccount = (() => {
  2.     let _ballance = 2000;
  3.     let deposit = (sum) => {
  4.         if (typeof sum !== 'number'){
  5.             throw error;
  6.         }
  7.         return _ballance =+ sum
  8.     }
  9.     let withdraw = (sum) => {
  10.  
  11.         if (typeof sum !== 'numner'){
  12.             throw new Error;
  13.         } else if ( sum > _ballance) {
  14.             throw console.error('No money no honey');
  15.         }
  16.         return _ballance += sum;
  17.     }
  18.  
  19.     let getBallance = () =>{
  20.         return _ballance
  21.     }
  22.  
  23.     return {
  24.         deposit,
  25.         withdraw,
  26.         getBallance
  27.     }
  28. })()
  29.  
  30. let account = bankAccount;
  31.  
  32. console.log( account.getBallance())
  33. account.deposit(1000);
  34. console.log( account.getBallance())
Advertisement
Add Comment
Please, Sign In to add comment