-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameOne.js
55 lines (48 loc) · 1.48 KB
/
GameOne.js
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
import React, { Component } from "react"
import ResultExtra from "./ResultExtra"
class GameOne extends Component {
constructor() {
super()
this.state = {
count: 0,
rand_num: Math.floor(Math.random() * 30),
passtest1: false
}
this.handleClick_inc = this.handleClick_inc.bind(this)
this.handleClick_dec = this.handleClick_dec.bind(this)
}
handleClick_inc() {
this.setState(prevState => {
return {
count: prevState.count + 1
}
})
}
handleClick_dec() {
this.setState(prevState => {
return {
count: prevState.count - 1
}
})
}
render() {
if (this.state.rand_num == this.state.count) {
this.state.passtest1 = true
}
if (this.state.rand_num != this.state.count) {
this.state.passtest1 = false
}
return (
<div className="game">
<h1>Drunk Test #1</h1>
<hr></hr>
<h3>Click me {this.state.rand_num} times!</h3>
<h1>{this.state.count}</h1>
<button onClick={this.handleClick_inc}>Increase!</button>
<button onClick={this.handleClick_dec}>Decrease!</button>
<ResultExtra passtest={this.state.passtest1} />
</div>
)
}
}
export default GameOne