Quiz.js 1.93 KB
Newer Older
Jiwon Yoon's avatar
quiz    
Jiwon Yoon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import React from 'react';
// import logo from './logo.svg';
// import './App.css';


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
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
    if (this.state.r === 1) {
      if (this.state.i === 3) {
        return (
          <div>
            <h2>수고하셨습니다!</h2>
          </div>
        )
      }
      else {
        return (
          <div className="quiz">
            <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 (
        <>
          <div className="App">
            <h1 style={{ background: "orange", display: "inline-block", border: "3px solid black", width: "200px" }}> Calculus</h1>
          </div>
          <div className="App">
            이름을 입력하세요
          <input onChange={(event) => { console.log(event.target.value) }} />
          </div>
          <button onClick={this.ShowQuiz1} style={{ margin: "30px", marginLeft: "690px", width: "150px", height: "30px", fontFamily: "impact" }}>Quiz Start !</button>
        </>

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

export default Quiz;