forked from WorldSpaceinc/quiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuizQuestion.tsx
44 lines (41 loc) · 879 Bytes
/
QuizQuestion.tsx
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
import React from "react";
import styles from "../styles/Home.module.css";
type Props = {
title: string;
text: string;
options: string[];
answerIndex: number;
setCorrect: () => void;
setFailed: (failed: boolean) => void;
};
export default function QuizQuestion({
title,
text,
options,
answerIndex,
setCorrect,
setFailed,
}: Props) {
function submitQuestion(submittedAnswer: number) {
if (answerIndex === submittedAnswer) {
setCorrect();
} else {
setFailed(true);
}
}
return (
<div>
<h2>{title}</h2>
<p>{text}</p>
{options.map((option, index) => (
<button
className={styles.quizQuestionButton}
onClick={() => submitQuestion(index)}
key={index}
>
{option}
</button>
))}
</div>
);
}