From ce7bb42a4ae2893b690df3789a0828af2e1652ab Mon Sep 17 00:00:00 2001 From: Paola Tramontin Date: Wed, 25 Nov 2020 16:13:56 -0500 Subject: [PATCH 1/2] finished hw --- src/App.js | 4 +- src/components/Calculator.js | 122 +++++++++++++++++++++++++++++++ src/components/ClassComponent.js | 13 ---- src/css/App.css | 20 +++++ 4 files changed, 144 insertions(+), 15 deletions(-) create mode 100644 src/components/Calculator.js delete mode 100644 src/components/ClassComponent.js diff --git a/src/App.js b/src/App.js index 993d922..524af5d 100644 --- a/src/App.js +++ b/src/App.js @@ -1,7 +1,7 @@ import React, { Component } from "react"; import FunctionalComponent from "./components/FunctionalComponent"; -import ClassComponent from "./components/ClassComponent"; +import Calculator from "./components/Calculator"; import "./css/App.css"; @@ -10,7 +10,7 @@ class App extends Component { return (
- +
); } diff --git a/src/components/Calculator.js b/src/components/Calculator.js new file mode 100644 index 0000000..fe667d2 --- /dev/null +++ b/src/components/Calculator.js @@ -0,0 +1,122 @@ +import React, { Component } from 'react' + +class Calculator extends Component { + + //the beginning value of the state and numbers is 0. + state= { + total: 0, + num1:0, + num2:0 + } + + + + setNum=(e, num)=>{ + console.log(e.target.value) + //the num is being given the target value, which is set by the user. + this.setState({ + [num]:e.target.value + }) + } + + + + //CODE TO ADD + getTotal=()=>{ + const grandTotal = parseInt(this.state.num1)+parseInt(this.state.num2) + this.setState({ + //num1:0 and num2:0 resets the values to 0 once button is pressed. In addition,its giving us the total. + num1:0, + num2:0, + total: grandTotal + }) + } + + //CODE TO ADD + minusTotal=()=>{ + const grandTotal = parseInt(this.state.minusNum1)-parseInt(this.state.minusNum2) + this.setState({ + //num1:0 and num2:0 resets the values to 0 once button is pressed. In addition,its giving us the total. + minusNum1:0, + minusNum2:0, + total2: grandTotal + }) + } + + + multiplyTotal=()=>{ + const grandTotal = parseInt(this.state.multiplyNum1)*parseInt(this.state.multiplyNum2) + this.setState({ + //num1:0 and num2:0 resets the values to 0 once button is pressed. In addition,its giving us the total. + multiplyNum1:0, + multiplyNum2:0, + total3: grandTotal + }) + } + + divideTotal=()=>{ + const grandTotal = parseInt(this.state.divideNum1)/parseInt(this.state.divideNum2) + this.setState({ + //num1:0 and num2:0 resets the values to 0 once button is pressed. In addition,its giving us the total. + divideNum1:0, + divideNum2:0, + total4: grandTotal + }) + } + + + render() { + return ( +
+ + {/* code below is to ADD */} +
+

Add with React!

+ this.setNum (e, 'num1')} /> + + + this.setNum(e, 'num2')} /> + +

Addition results go here!

+

{this.state.total}

+
+ + {/* code below is to subtract */} +
+

subtract with React!

+ this.setNum (e, 'minusNum1')} /> + - + this.setNum(e, 'minusNum2')} /> + +

subtraction results go here!

+

{this.state.total2}

+
+ + {/* code below is to multiply */} +
+

Multiply with React!

+ this.setNum (e, 'multiplyNum1')} /> + * + this.setNum(e, 'multiplyNum2')} /> + +

subtraction results go here!

+

{this.state.total3}

+
+ + {/* code below is to multiply */} +
+

Divide with React!

+ this.setNum (e, 'divideNum1')} /> + / + this.setNum(e, 'divideNum2')} /> + +

Division results go here!

+

{this.state.total4}

+
+ + +
+ ) + } +} + +export default Calculator diff --git a/src/components/ClassComponent.js b/src/components/ClassComponent.js deleted file mode 100644 index fdf0e4f..0000000 --- a/src/components/ClassComponent.js +++ /dev/null @@ -1,13 +0,0 @@ -import React, { Component } from 'react' - -class ClassComponent extends Component { - render() { - return ( -
- Class Component -
- ) - } -} - -export default ClassComponent diff --git a/src/css/App.css b/src/css/App.css index 4931613..6d57e25 100644 --- a/src/css/App.css +++ b/src/css/App.css @@ -1,3 +1,23 @@ .App { text-align: center; } + +.container{ + display:flex-start; +} + +.add{ + background-color:rgb(200, 192, 192); +} + +.subtract{ + background-color:yellow; +} + +.multiply{ + background-color:green; +} + +.divide{ + background-color:pink; +} \ No newline at end of file From fa4597dccb41bd6f70b9d20e80af6c1b386d573d Mon Sep 17 00:00:00 2001 From: Paola Tramontin Date: Tue, 1 Dec 2020 15:17:03 -0500 Subject: [PATCH 2/2] finished extra assignments --- src/components/Calculator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Calculator.js b/src/components/Calculator.js index fe667d2..afb76d6 100644 --- a/src/components/Calculator.js +++ b/src/components/Calculator.js @@ -32,7 +32,7 @@ class Calculator extends Component { }) } - //CODE TO ADD + //CODE TO SUBTRACT minusTotal=()=>{ const grandTotal = parseInt(this.state.minusNum1)-parseInt(this.state.minusNum2) this.setState({ @@ -98,7 +98,7 @@ class Calculator extends Component { * this.setNum(e, 'multiplyNum2')} /> -

subtraction results go here!

+

Multiplication results go here!

{this.state.total3}