JavaScript BankAccount Function

Create a BankAccount class that returns an object. Inside this function, follow these steps:

  • Initialize Balance:
    • Create a balance variable and initialize it to 100, or any balance you choose (representing $100).
  • Methods:
    • deposit(amount): Adds a specified amount to the balance.
    • withdraw(amount): Deducts a specified amount from the balance.
    • getBalance(): Returns the current balance.
    • transfer(ammount): Transfers a specified amount from one account to another.
  • Encapsulation:
    • Only allow access to the balance variable through the deposit, withdraw, and getBalance methods.
    • Avoid direct access to balance from outside the BankAccount function.
  • Validation:
    • A deposit can only add positive amounts.
    • A withdrawal can only occur if the amount is available in the balance.
  • Testing:
    • Test the account by creating a new BankAccount instance.
    • Call each method to verify functionality.
  • Inheritance:
    • Create accounts that can transfer money to eachother
%%js 
    class BankAccount {

    }
<IPython.core.display.Javascript object>