Account Balance

Enter an amount:

Your Balance: $0.00

Transaction History

Link to AccountBalance.js

Basic Instructions:

1. Create a global variable called accountBalance. Initialize it to 0.

2. The input amount field should follow the following rules:

  1. The amount cannot be negative. If so, display an error message "Amount cannot be negative.".

3. Create a deposit function that will process a deposit to the account.

  1. This will add the amount entered in the Amount field to the accountBalance.
  2. Display the updated balance.

4. Create a withdraw function that will process a withdrawl from the account.

  1. The amount entered cannot be less than the balance amount. If so, display an error message "Cannot withdraw more than you have!".
  2. This will subtract the amount entered in the Amount field from the accountBalance.
  3. Display the updated balance.

5. Create a displayBalance function that will display the current value of accountBalance in the Balance field.

  1. The balance amount displayed to the page should be formatted as currency.
  2. Call this function whenever a deposit or withdrawal is processed to display the current balance.
  3. Call this function from the Balance button.

6. Use the combined operators for the deposit and withdraw processes.

7. Use parseInt( ) or parseFloat( ) as needed.

Intermediate Instructions:

  1. Use a JavaScript object to store the account information.
  2. Validate the input amount. It must be a number. If not, display an error message "Please enter a number.".

Advanced Instructions:

  1. Use the AccountBalance class from the assignments to store the information.
  2. Captures the transactions. Add a button that will display the transactions on the screen.