I have an array, that represents the question numbers.
There is an another object array, that contains user answer (question number and whether user's answer is correct or wrong).
questions = [] // question numbers
validity = [{answer: true, questionNo: "2"},{answer: false, questionNo: "3"}] // user answers array
What i'm trying to do is, highlight correct questions with green color and wrong questions with red color.
I tried below when validity array has two records, however, it only highlited last record:
{
questions.map((i, index) => {
let className = '';
if (validity) {
validity.map((data) => {
if (Object.keys(data).length) {
if ((Number(data.questionNo) === index)) {
if (data.answer) {
className = `question-list correct-q` // when answer `true`,set div to green color
} else {
className = `question-list wrong-q` // when answer `false`,set div to red
}
} else {
className = `question-list` // default div color
}
}
})
} else {
className = `question-list`
}
return (index != 0) &&
<div
className={className}
key={index}
onClick={() => onclickQuestion(index)}
>
Q - {index}
</div>
})
}
I want to color Q-2 with green color and Q-3 with red color at same time.
