-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
80 lines (70 loc) · 2.84 KB
/
App.js
File metadata and controls
80 lines (70 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React from "react";
import Button from "./components/Button";
import Input from "./components/Input";
import Clear from "./components/Clear";
class App extends React.Component {
state = {input: "", preNum: "", op: ""};
addToInput = val => {
this.setState({input: this.state.input + val})
}
addZeroInput = val => {
if(this.state.input !== "") {
this.setState({input: this.state.input + val})
}
}
addDecimal = val => {
if(this.state.input.indexOf(".") == -1) {
this.setState({input: this.state.input + val})
}
}
clearInput = () => {
this.setState({input: ""})
}
add = () => {
this.setState({preNum: this.state.input, input: "", op: "+"});
}
eval = () => {
if (this.state.op === "+") {
this.setState({input: parseFloat(this.state.preNum) + parseFloat(this.state.input)})
}
}
render() {
return(
<div className="app">
<div className="calc-wrapper">
<div className="row">
<Input in={this.state.input}></Input>
</div>
<div className="row">
<Button handleClick={this.addToInput} id="7"></Button>
<Button handleClick={this.addToInput} id="8"></Button>
<Button handleClick={this.addToInput} id="9"></Button>
<Button id="/"></Button>
</div>
<div className="row">
<Button handleClick={this.addToInput} id="4"></Button>
<Button handleClick={this.addToInput} id="5"></Button>
<Button handleClick={this.addToInput} id="6"></Button>
<Button id="*"></Button>
</div>
<div className="row">
<Button handleClick={this.addToInput} id="1"></Button>
<Button handleClick={this.addToInput} id="2"></Button>
<Button handleClick={this.addToInput} id="3"></Button>
<Button handleClick={this.add} id="+"></Button>
</div>
<div className="row">
<Button handleClick={this.addDecimal} id="."></Button>
<Button handleClick={this.addZeroInput} id="0"></Button>
<Button handleClick={this.eval} id="="></Button>
<Button id="-"></Button>
</div>
<div className="row">
<Clear handleClick={this.clearInput} id="Clear"></Clear>
</div>
</div>
</div>
)
}
}
export default App;