Quiz.js 2.49 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
18
    this.ShowQuiz = this.ShowQuiz.bind(this)
    this.state = { ...question[0], i: 0, v: "", r: 0, c: "" }
Jiwon Yoon's avatar
Jiwon Yoon committed
19
  }
Jiwon Yoon's avatar
d    
Jiwon Yoon committed
20
21
  ShowQuiz() {
    this.setState({  r: 1 })
Jiwon Yoon's avatar
quiz    
Jiwon Yoon committed
22
23
  }
  setQuestion() {
Jiwon Yoon's avatar
Jiwon Yoon committed
24
    this.setState({ ...question[this.state.i + 1], i: this.state.i + 1, v: "" })
Jiwon Yoon's avatar
quiz    
Jiwon Yoon committed
25
  }
Jiwon Yoon's avatar
d    
Jiwon Yoon committed
26
27
28
29
30
31
  // setAnswer(e) {
  //   question[this.state.i]["A"] = e.target.value
  //   this.setState({ v: e.target.value })
  //   console.log(this.state)
  //   console.log(question)
  // }
Jiwon Yoon's avatar
quiz    
Jiwon Yoon committed
32
  render() {
Jiwon Yoon's avatar
Jiwon Yoon committed
33
34
35
36
37
38
39
40
41
42
    if (this.state.r === 1) {
      if (this.state.i === 3) {
        return (
          <div>
            <h2>수고하셨습니다!</h2>
          </div>
        )
      }
      else {
        return (
Jiwon Yoon's avatar
push    
Jiwon Yoon committed
43
          <div className="Quiz">
Jiwon Yoon's avatar
Jiwon Yoon committed
44
            <h2>Q:{this.state.Q}</h2>
Jiwon Yoon's avatar
d    
Jiwon Yoon committed
45
46
47
48
49
50
51
52
53
54
55
56
57
            <div> {this.state.Choose[0]}</div>
            <div> {this.state.Choose[1]}</div>
            <div> {this.state.Choose[2]}</div>
            <div> {this.state.Choose[3]}</div>
            <div className="App">
              정답을 입력하세요
              <select>
                <option hidden disabled selected>정답선택</option>
                <option value={this.state.Choose[0]}></option>
                <option value={this.state.Choose[1]}></option>
                <option value={this.state.Choose[2]}></option>
                <option value={this.state.Choose[3]}></option>
              </select>
Jiwon Yoon's avatar
Jiwon Yoon committed
58
            </div>
Jiwon Yoon's avatar
d    
Jiwon Yoon committed
59
60
61
            {/* <div>
              <input type="text" value={this.state.v} name="A" onChange={this.setAnswer} />
            </div> */}
Jiwon Yoon's avatar
Jiwon Yoon committed
62
63
64
65
66
67
68
            <button type="button" onClick={this.setQuestion}>다음 문제로</button>
          </div>
        )
      }
    }
    else {
      return (
Jiwon Yoon's avatar
push    
Jiwon Yoon committed
69
70
71
        <div className="Box">
          <div className="Main">
            <h1> Calculus</h1>
Jiwon Yoon's avatar
Jiwon Yoon committed
72
          </div>
Jiwon Yoon's avatar
push    
Jiwon Yoon committed
73
          <div className="Name">
Jiwon Yoon's avatar
Jiwon Yoon committed
74
75
76
            이름을 입력하세요
          <input onChange={(event) => { console.log(event.target.value) }} />
          </div>
Jiwon Yoon's avatar
d    
Jiwon Yoon committed
77
          <button className="QuizStart" onClick={this.ShowQuiz}>Quiz Start !</button>
Jiwon Yoon's avatar
push    
Jiwon Yoon committed
78
        </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
79
80
81

      )
    }
Jiwon Yoon's avatar
quiz    
Jiwon Yoon committed
82
83
84
85
  }
}

export default Quiz;