This question already has an answer here:
- How can I shuffle an array? [duplicate] 2 answers
Hi Thanks for reading.
I am struggling to show 4 answers randomly in my quiz app project now.
The data is as follows;
const questions = [ { question: "What is the fifth planet from the sun?", answers: [ { id: "1", text: "Mars" }, { id: "2", text: "Jupiter", correct: true }, { id: "3", text: "Saturn" }, { id: "4", text: "Venus" } ] }, { question: "How many planets are in the Solar System?", answers: [ { id: "1", text: "6" }, { id: "2", text: "7" }, { id: "3", text: "8", correct: true }, { id: "4", text: "9" } ] } ]; export default questions;
The view code is as follows;
View
<Text style={styles.text}>{question.question}</Text>
<ButtonContainer>
{question.answers.map(answer => (
<Button
key={answer.id}
text={answer.text}
onPress={() => this.answer(answer.correct)}
/>
))}
</ButtonContainer>
View