forked from caike/React-QuizComponent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuizQuestion.js
More file actions
36 lines (33 loc) · 1.04 KB
/
QuizQuestion.js
File metadata and controls
36 lines (33 loc) · 1.04 KB
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 QuizQuestionButton from './QuizQuestionButton'
class QuizQuestion extends Component {
constructor(props) {
super(props)
this.state = { incorrectAnswer: false }
}
handleClick(button_text) {
if (button_text === this.props.quiz_question.answer) {
this.setState({ incorrectAnswer: false })
this.props.showNextQuestionHandler()
} else {
this.setState({ incorrectAnswer: true })
}
}
render() {
return (
<main>
<section>
<p>{this.props.quiz_question.instruction_text}</p>
</section>
<section className="buttons">
<ul>{this.props.quiz_question.answer_options.map((answer, index) => {
return <QuizQuestionButton button_text={answer} key={index} clickHandler={this.handleClick.bind(this)} />
})}
</ul>
</section>
{this.state.incorrectAnswer ? <p className='error'>Sorry, that's not right</p> : null}
</main>
)
}
}
export default QuizQuestion