-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
Copy pathQuiz.js
36 lines (30 loc) · 947 Bytes
/
Quiz.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
import React, { Component } from "react";
import QuizQuestion from "./QuizQuestion.js";
import QuizEnd from "./QuizEnd.js";
let quiz_data = require("./quiz_data.json");
class Quiz extends Component {
constructor(props){
super(props);
this.state = quiz_data;
}
handleClick(){
console.log("hey");
this.setState((state) => {
return { quiz_position: state.quiz_position + 1 }
});
}
handleResetClick(){
this.setState({ quiz_position: 1 });
}
render(){
const isQuizEnd = (this.state.quiz_position - 1 === this.state.quiz_questions.length);
return (<div>
{isQuizEnd ? <QuizEnd resetClickHandler={this.handleResetClick.bind(this)} /> :
<QuizQuestion
clickHandler={this.handleClick.bind(this)}
quiz_question={this.state.quiz_questions[this.state.quiz_position-1]} />
}
</div>);
}
}
export default Quiz