#Mapping Data from API
1 messages · Page 1 of 1 (latest)
You're getting there. So data.results is an array of objects. If you console.log(data.results[0]) you will see the first object and within that object you'll see the question, correct answer, and incorrect answers. When I started this project I just fetched two questions. You're placing the array of questions info into a state variable. Next you can map over that state (array of questions) to work with each question separately. You might call a <Question /> component... setting a unique key and sending props info you need to display the question and multiple-choice answers.
Thanks man ! i will try that
when i console.log(data.results.question) to check it says undefied
try console.log(data.results[0].question) ... to reference the question within the first object in the array of "questions" objects, i.e. each object within the array contains info for a question.
Thanks you for your response bro , I successfully rendered questions to UI but how can I render my Choices? its like correct_answer : "something" and rest are stored as incorrect_answers : "","",""
here it is
combine correct answer and incorrect answers... then sort them (you decide how) so which choice is the correct answer is not obvious, i.e. always the first choice. Then you can list the choices as buttons.
hey, could you describe future steps, please? Like this one that questions shjould bne put into State? I'm currently stuck on printing those questions and im not sure how to write a functionality to check them
Hey I hope this helps not trying to give the answer right away but it took me a while to figure out as well. When your combining the incorrect answer and correct answer your return syntax can look like this,
return {
answer: [object.correct_answer, ...object.incorrect_answer]
}
Hey, I got it actually, the problem is how should I add the functionality to choose answers by user and then check if it's correct or not