You will complete all of these challenges in the same file.
- Create a new class
BankAccountwith attributesownerNameandbalanceownerNameshould be passed in to the constructorbalanceshould be initialized as0
- Create a new instance of the class for an imaginary person,
person
-
Create a method
depositthat takes one argument,amount. The method should increase the balance by that amount. -
Call
person.deposit(100)and then console logperson.balance. It should say 100. -
Now do the same, with a
withdawmethod that reduces the balance.- Don't let people overdraft! Have the
withdrawmethod first check the balance, and if there isn't enough money, cancel the transaction and print a message that says "Insufficient Funds"
- Don't let people overdraft! Have the
- What happens if you give the deposit and withdraw methods arguments that are not numbers? Can you handle those cases?
- What happens if you pass a negative number to the
depositmethod? Can your method detect that situation, and callthis.withdrawinstead? (Math.abs() might help you here.) - Can you keep a log of the user's transactions? Try storing this information in whatever way seems appropriate to you.
- How about a
printTransactionsmethod that gives the users a nicely formatted list of transations?
- How about a