Quiz.js 1.96 KB
Newer Older
Jiwon Yoon's avatar
quiz    
Jiwon Yoon committed
1
2
import React from 'react';
// import logo from './logo.svg';
Jiwon Yoon's avatar
push    
Jiwon Yoon committed
3
import './Quiz.css';
Jiwon Yoon's avatar
quiz    
Jiwon Yoon committed
4
5
6


const question = [
Jiwon Yoon's avatar
d    
Jiwon Yoon committed
7
8
9
  { Q: "6 X 4 ?", Choose: [6, 12, 18, 24], A: "" },
  { Q: "3 + 3 ?", Choose: [2, 4, 6, 8], A: "" },
  { Q: "3 - 1 ?", Choose: [1, 2, 3, 4], A: "" }
Jiwon Yoon's avatar
quiz    
Jiwon Yoon committed
10
11
12
13
14
]

class Quiz extends React.Component {
  constructor(props) {
    super(props)
Jiwon Yoon's avatar
d    
Jiwon Yoon committed
15
    // this.setAnswer = this.setAnswer.bind(this)
Jiwon Yoon's avatar
quiz    
Jiwon Yoon committed
16
    this.setQuestion = this.setQuestion.bind(this)
Jiwon Yoon's avatar
d    
Jiwon Yoon committed
17
    this.ShowQuiz = this.ShowQuiz.bind(this)
Jiwon Yoon's avatar
a    
Jiwon Yoon committed
18
19
20
21
22
23
    this.state = {
      ...question[0],
      i: 0,
      page: 0,
      list: ""
    }
Jiwon Yoon's avatar
Jiwon Yoon committed
24
  }
Jiwon Yoon's avatar
d    
Jiwon Yoon committed
25
  ShowQuiz() {
Jiwon Yoon's avatar
asdf    
Jiwon Yoon committed
26
    this.setState({ page: 1 })
Jiwon Yoon's avatar
quiz    
Jiwon Yoon committed
27
28
  }
  setQuestion() {
Jiwon Yoon's avatar
asdf    
Jiwon Yoon committed
29
    this.setState({ ...question[this.state.i + 1], i: this.state.i + 1})
Jiwon Yoon's avatar
quiz    
Jiwon Yoon committed
30
31
  }
  render() {
Jiwon Yoon's avatar
a    
Jiwon Yoon committed
32
33
    if (this.state.page === 1) {
      if (this.state.i === question.length) {
Jiwon Yoon's avatar
Jiwon Yoon committed
34
35
36
37
38
39
40
41
        return (
          <div>
            <h2>수고하셨습니다!</h2>
          </div>
        )
      }
      else {
        return (
Jiwon Yoon's avatar
push    
Jiwon Yoon committed
42
          <div className="Quiz">
Jiwon Yoon's avatar
Jiwon Yoon committed
43
            <h2>Q:{this.state.Q}</h2>
Jiwon Yoon's avatar
asdf    
Jiwon Yoon committed
44
45
46
47
48
            {this.state.Choose.map((a) =>
              <div>
                <input type="radio" name="a" id={a} value={a} />
                <label for={a}>{a}</label>
              </div>)}
Jiwon Yoon's avatar
d    
Jiwon Yoon committed
49
50
            <div className="App">
              정답을 입력하세요
Jiwon Yoon's avatar
Jiwon Yoon committed
51
            </div>
Jiwon Yoon's avatar
d    
Jiwon Yoon committed
52
53
54
            {/* <div>
              <input type="text" value={this.state.v} name="A" onChange={this.setAnswer} />
            </div> */}
Jiwon Yoon's avatar
a    
Jiwon Yoon committed
55
            <button type="button" onClick={this.setQuestion}>다음</button>
Jiwon Yoon's avatar
Jiwon Yoon committed
56
57
58
59
60
61
          </div>
        )
      }
    }
    else {
      return (
Jiwon Yoon's avatar
push    
Jiwon Yoon committed
62
63
64
        <div className="Box">
          <div className="Main">
            <h1> Calculus</h1>
Jiwon Yoon's avatar
Jiwon Yoon committed
65
          </div>
Jiwon Yoon's avatar
push    
Jiwon Yoon committed
66
          <div className="Name">
Jiwon Yoon's avatar
Jiwon Yoon committed
67
68
69
            이름을 입력하세요
          <input onChange={(event) => { console.log(event.target.value) }} />
          </div>
Jiwon Yoon's avatar
d    
Jiwon Yoon committed
70
          <button className="QuizStart" onClick={this.ShowQuiz}>Quiz Start !</button>
Jiwon Yoon's avatar
push    
Jiwon Yoon committed
71
        </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
72
73
74

      )
    }
Jiwon Yoon's avatar
quiz    
Jiwon Yoon committed
75
76
77
78
  }
}

export default Quiz;