Help me to pass Handling quiz end React Test. I have been trying from 5 hours but unable to pass last challenge
Asked by Mithlesh Kumar about 2 years ago
I have tried whatever i know but still i'm unable to solve the last challenge which shows Uncaught TypeError: Cannot read properties of undefined (reading 'questionText') Help me Guys.
Linkhttps://codedamn.com/learn/reactjs/react-quiz-project/idsqjGMlx6fqE54xtE7km
1 Answer
If you follows the instruction of the quiz, the bug was intended for you to fix.
The bug caused React to throw error when it try to iterate over the questions array.
So when you finished answering the last question, it break the application because it try to show the next question that is not exist.
So what you need to do is to handle it, everytime you answer the question the handleAnswerClick
function was invoked and the currentIndex
will be incremented.
From this, you can stop it to show the next question by checking if the currentIndex
is the same as the total number of question and set the quizFinished
state to true
.
Hope this will help you.