-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathQuestions.js
More file actions
55 lines (40 loc) · 1.45 KB
/
Questions.js
File metadata and controls
55 lines (40 loc) · 1.45 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React from "react";
import { decode } from 'he';
class Questions extends React.Component {
constructor() {
super();
}
componentDidMount(){
this.props.fetchQuestion()
}
render() {
console.log(this.props.questions)
let answerList = (this.props.questions.incorrect_answers === undefined)
?
null :
[...this.props.questions.incorrect_answers, this.props.questions.correct_answer]
.sort(function() { return 0.5 - Math.random() })
.map((answer) =>
<button className ="voting-button" key={answer} onClick={() => this.props.clickHandler(this.props.questions.correct_answer === answer)}>{answer}</button>
);
let questionDecoded = (this.props.questions.question === undefined) ? null : decode(this.props.questions.question)
// decoding HTML entities in questions using 'he' - ternary to cover initial undefined state.
return (
<div className="quiz__display"
style = {{backgroundImage: `url(${this.props.image})`}}>
<div>
<h2>{questionDecoded}</h2>
<ul>{answerList}</ul>
</div>
</div>
);
}
}
// {this.props.questions.length > 0 ?
// <div key={this.props.questions.question}>
// <h2 key={this.props.questions.question}>
// {this.props.questions.question}</h2>
// {this.props.questions.incorrect_answers}
// </div> :
// <h3>I haven't fetched yet</h3>}
export default Questions;