Quiz.js 1.77 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
7
8
9
10
11
12
13
14
15
16


const question = [
  { Q: "당신의 성별은?", A: "" },
  { Q: "당신의 이름은?", A: "" },
  { Q: "당신의 점수는?", A: "" }
]

class Quiz extends React.Component {
  constructor(props) {
    super(props)
    this.setAnswer = this.setAnswer.bind(this)
    this.setQuestion = this.setQuestion.bind(this)
Jiwon Yoon's avatar
Jiwon Yoon committed
17
18
19
20
21
    this.ShowQuiz1 = this.ShowQuiz1.bind(this)
    this.state = { ...question[0], i: 0, v: "", r: 0 }
  }
  ShowQuiz1() {
    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
26
27
  }
  setAnswer(e) {
    question[this.state.i]["A"] = e.target.value
Jiwon Yoon's avatar
Jiwon Yoon committed
28
    this.setState({ v: e.target.value })
Jiwon Yoon's avatar
quiz    
Jiwon Yoon committed
29
30
31
32
    console.log(this.state)
    console.log(question)
  }
  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
45
46
47
48
49
50
51
52
53
54
            <h2>Q:{this.state.Q}</h2>
            <div>
              <input type="text" value={this.state.v} name="A" onChange={this.setAnswer} />
            </div>
            <button type="button" onClick={this.setQuestion}>다음 문제로</button>
          </div>
        )
      }
    }
    else {
      return (
Jiwon Yoon's avatar
push    
Jiwon Yoon committed
55
56
57
        <div className="Box">
          <div className="Main">
            <h1> Calculus</h1>
Jiwon Yoon's avatar
Jiwon Yoon committed
58
          </div>
Jiwon Yoon's avatar
push    
Jiwon Yoon committed
59
          <div className="Name">
Jiwon Yoon's avatar
Jiwon Yoon committed
60
61
62
            이름을 입력하세요
          <input onChange={(event) => { console.log(event.target.value) }} />
          </div>
Jiwon Yoon's avatar
push    
Jiwon Yoon committed
63
64
          <button className="QuizStart" onClick={this.ShowQuiz1}>Quiz Start !</button>
        </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
65
66
67

      )
    }
Jiwon Yoon's avatar
quiz    
Jiwon Yoon committed
68
69
70
71
  }
}

export default Quiz;