WDV221 Intro Javascript

Calculations and Textfields

Create an ATM

In this project you are going to create an electronic checkbook using Javascript. You can add amounts and withdraw amounts from your current balance.

Enter an amount:

Your Balance:

Instructions:

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

2. The amount field should follow the following rules:

  1. It must be a number. If not, display an error message "Please enter a number.".
  2. The amount cannot be negative. If so, display an error message "Amount cannot be negative.".
  3. Display the updated balance.

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.

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 update balance.

5. Create a displayBalance function that will display the current value of accountBalance in the Balance field. The balance amount displayed to the page should be formatted as currency. Call this function whenever a deposit or withdrawal is processed. 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.