diff --git a/src/Account/index.js b/src/Account/index.js index 6f34bb6..8184b37 100644 --- a/src/Account/index.js +++ b/src/Account/index.js @@ -2,14 +2,46 @@ import React, { Component } from 'react'; class Account extends Component { + constructor(props){ + super(props); + this.state = { + balance: 0 + } + this.handleDepositClick = this.handleDepositClick.bind(this) + this.handleWithdrawClick = this.handleWithdrawClick.bind(this) + } + handleDepositClick(e) { + e.preventDefault(); + const amount = parseInt(this.inputBox.value); + const newBalance = this.state.balance + amount; + this.setState({ + balance: newBalance + }) + this.inputBox.value = ''; + } + handleWithdrawClick(e){ + e.preventDefault(); + const amount = parseInt(this.inputBox.value); + const newBalance = this.state.balance - amount; + if(newBalance >= 0) { + this.setState({ + balance: newBalance + }); + } + this.inputBox.value = ''; + } render() { + let balanceClass = 'balance'; + if(this.state.balance === 0) { + balanceClass = 'zero' + } return (