Skip to content

Commit 0e26972

Browse files
committed
checkAnswer
1 parent efe1161 commit 0e26972

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/App.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ import SetupForm from "./SetupForm";
55
import Loading from "./Loading";
66
import Modal from "./Modal";
77
function App() {
8-
const { waiting, loading, questions, index, correct, nextQuestion } =
9-
useGlobalContext();
8+
const {
9+
waiting,
10+
loading,
11+
questions,
12+
index,
13+
correct,
14+
nextQuestion,
15+
checkAnswer,
16+
} = useGlobalContext();
1017

1118
if (waiting) {
1219
return <SetupForm></SetupForm>;
@@ -34,6 +41,9 @@ function App() {
3441
<button
3542
key={index}
3643
className="answer-btn"
44+
onClick={() => {
45+
checkAnswer(correct_answer === answer);
46+
}}
3747
dangerouslySetInnerHTML={{ __html: answer }}
3848
></button>
3949
);

src/context.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ const AppProvider = ({ children }) => {
5959
});
6060
};
6161

62+
const checkAnswer = (value) => {
63+
if (value) {
64+
setCorrect((oldValue) => oldValue + 1);
65+
}
66+
nextQuestion();
67+
};
68+
6269
useEffect(() => {
6370
fetchQuestions(tempUrl);
6471
}, []);
@@ -74,6 +81,7 @@ const AppProvider = ({ children }) => {
7481
error,
7582
isModalOpen,
7683
nextQuestion,
84+
checkAnswer,
7785
}}
7886
>
7987
{children}

0 commit comments

Comments
 (0)