From 95c02737c026b6bfa37e740f2ad6b034a80a813d Mon Sep 17 00:00:00 2001 From: Chris Roman Date: Mon, 29 Oct 2018 21:33:13 -0500 Subject: [PATCH] completed homework --- src/Account/index.js | 42 +++++++++++++++++++++++++++++++++++++----- src/App.js | 4 ++-- 2 files changed, 39 insertions(+), 7 deletions(-) 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 (
-

TODO: CHANGE TO PROP

-
$0
- - - +

{this.props.name}

+
{this.state.balance}
+ this.inputBox = input} /> + +
) } diff --git a/src/App.js b/src/App.js index ae32dbb..04fa98d 100644 --- a/src/App.js +++ b/src/App.js @@ -10,8 +10,8 @@ class App extends Component {
Bank of GA
- - + +
);