├── banking.html ├── index.html └── js └── banking.js /banking.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Banking Page 9 | 10 | 11 | 12 | 13 |
14 |

Let's get some Moooooney!!!

16 |
17 |
18 | 19 |
20 |
21 |
22 |

Deposit

23 |

$00

24 |
25 |
26 |

Withdraw

27 |

$00

28 |
29 |
30 |

Balance

31 |

$1240

32 |
33 | 34 |
35 |
36 | 37 |
38 |
39 |
40 |

Please Deposit

41 |
42 | 44 | 46 |
47 |
48 |
49 |

Please Withdraw

50 |
51 | 53 | 55 |
56 |
57 |
58 |
59 |
60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Baap Er Bank 9 | 10 | 11 | 12 | 13 | 14 |
15 |

Welcome to my Baap-Er-Bank!!!

17 |
18 |
19 |
20 |

Please Login

21 |
22 | 24 | 26 | 27 |
28 |
29 |
30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /js/banking.js: -------------------------------------------------------------------------------- 1 | function doubleIt(num) { 2 | const result = num * 2; 3 | return result; 4 | } 5 | const fiveDouble = doubleIt(5); 6 | const severDouble = doubleIt(7); 7 | 8 | function getInputValue(inputId) { 9 | debugger; 10 | const inputField = document.getElementById(inputId); 11 | const inputAmountText = inputField.value; 12 | const amountValue = parseFloat(inputAmountText); 13 | // clear input field 14 | inputField.value = ''; 15 | return amountValue; 16 | } 17 | 18 | function updateTotalField(totalFieldId, amount) { 19 | // debugger; 20 | const totalElement = document.getElementById(totalFieldId); 21 | const totalText = totalElement.innerText; 22 | const previousTotal = parseFloat(totalText); 23 | totalElement.innerText = previousTotal + amount; 24 | } 25 | 26 | function getCurrentBalance() { 27 | const balanceTotal = document.getElementById('balance-total'); 28 | const balanceTotalText = balanceTotal.innerText; 29 | const previousBalanceTotal = parseFloat(balanceTotalText); 30 | return previousBalanceTotal; 31 | } 32 | 33 | function updateBalance(amount, isAdd) { 34 | const balanceTotal = document.getElementById('balance-total'); 35 | /* 36 | const balanceTotalText = balanceTotal.innerText; 37 | const previousBalanceTotal = parseFloat(balanceTotalText); */ 38 | const previousBalanceTotal = getCurrentBalance(); 39 | if (isAdd == true) { 40 | balanceTotal.innerText = previousBalanceTotal + amount; 41 | } 42 | else { 43 | balanceTotal.innerText = previousBalanceTotal - amount; 44 | } 45 | } 46 | 47 | document.getElementById('deposit-button').addEventListener('click', function () { 48 | /* 49 | const depositInput = document.getElementById('deposit-input'); 50 | const depositAmountText = depositInput.value; 51 | const depositAmount = parseFloat(depositAmountText); */ 52 | 53 | 54 | // get and update deposit total 55 | /* 56 | const depositTotal = document.getElementById('deposit-total'); 57 | const depositTotalText = depositTotal.innerText; 58 | const previousDepositTotal = parseFloat(depositTotalText); 59 | 60 | depositTotal.innerText = previousDepositTotal + depositAmount; */ 61 | 62 | 63 | // update balance 64 | /* 65 | const balanceTotal = document.getElementById('balance-total'); 66 | const balanceTotalText = balanceTotal.innerText; 67 | const previousBalanceTotal = parseFloat(balanceTotalText); 68 | balanceTotal.innerText = previousBalanceTotal + depositAmount; */ 69 | const depositAmount = getInputValue('deposit-input'); 70 | if (depositAmount > 0) { 71 | updateTotalField('deposit-total', depositAmount); 72 | updateBalance(depositAmount, true); 73 | } 74 | }); 75 | 76 | // handle withdraw button 77 | document.getElementById('withdraw-button').addEventListener('click', function () { 78 | /* 79 | const withdrawInput = document.getElementById('withdraw-input'); 80 | const withdrawAmountText = withdrawInput.value; 81 | const withdrawAmount = parseFloat(withdrawAmountText); */ 82 | 83 | 84 | // get and update withdraw total 85 | /* 86 | const withdrawTotal = document.getElementById('withdraw-total'); 87 | const previousWithdrawTotalText = withdrawTotal.innerText; 88 | const previousWithdrawTotal = parseFloat(previousWithdrawTotalText); 89 | 90 | withdrawTotal.innerText = previousWithdrawTotal + withdrawAmount; */ 91 | 92 | 93 | // update balance after withdraw 94 | /* 95 | const balanceTotal = document.getElementById('balance-total'); 96 | const balanceTotalText = balanceTotal.innerText; 97 | const previousBalanceTotal = parseFloat(balanceTotalText); 98 | 99 | balanceTotal.innerText = previousBalanceTotal - withdrawAmount; */ 100 | 101 | const withdrawAmount = getInputValue('withdraw-input'); 102 | const currentBalance = getCurrentBalance(); 103 | if (withdrawAmount > 0 && withdrawAmount < currentBalance) { 104 | updateTotalField('withdraw-total', withdrawAmount); 105 | updateBalance(withdrawAmount, false); 106 | } 107 | if (withdrawAmount > currentBalance) { 108 | console.log('You can not withdraw more than what you have in your account'); 109 | } 110 | }); --------------------------------------------------------------------------------