Skip to content

Commit

Permalink
Update Questions.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
Ibrahim-Halil-Kuray committed Oct 29, 2023
1 parent 5c47271 commit a1a26a9
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/components/Questions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,32 @@ const Questions: React.FC<QuestionsProps> = ({ apiUrl }) => {
});
}, [apiUrl]);

useEffect(() => {
let interval: NodeJS.Timeout;

if (timer > 0 && currentQuestionIndex < questions.length && !isTimeUp) {
interval = setInterval(() => {
if (timer > 0) {
setTimer(timer - 1);
} else {
clearInterval(interval);
setIsTimeUp(true);
// when time is up, next q
goToNextQuestion();
}
}, 1000);
}
return () => {
clearInterval(interval);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [timer, currentQuestionIndex, questions, isTimeUp]);
const handleAnswerQuestion = (selectedOption: number) => {
const correctAnswer = questions[currentQuestionIndex].correct_answer;
setUserAnswers([...userAnswers, selectedOption === correctAnswer ? 1 : 0]);
setIsAnswered(true);
};

return <div></div>;
};

Expand Down

0 comments on commit a1a26a9

Please sign in to comment.