You are returning an object of answer {number, answer, isCorrect}
you should just map into answer after mapping into question:
render() {
// add logic and constant here
return (
//... add another component or jsx
<div className='show-score'>{showScore}</div>
<div className='quiz-window'>
{this.state.questions.map((question, index) => (
<div key={index}>
{question.title}
<div className='answer-section'>
{question.answers.map(answer => (
<button key={answer.number} onClick={() => this.handleAnswerOptionClick(answer.isCorrect)}>
{answer.answer}
</button>
))}
</div>
</div>
))}
</div>
//... add another component or jsx
)
}
Bonus: For randomizing items inside array Instead of:
let randomizedResult = [];
for (let i = 0; i < amountOfQuestions; i++) {
let randomIndex = Math.floor(Math.random() * result.length);
randomizedResult.push(result[randomIndex]);
result.splice(randomIndex, 1);
}
Use this code:
const randomizedResult = result.sort(() => Math.random() - 0.5)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…