I am displaying results of a quiz and want it to show a green correct or a red incorrect beside the corresponding question. I have a PHP file holding the questions, that returns true or false depending on whether the users answer was correct or not. My code below shows how my results are shown (in a table, with true or false being shown). I've tried an if statement to say if that field equals true, make it green, else red. But nothing works. I just want to transform 'true' into a green 'correct' and 'false' into a red incorrect using jQuery.
Related JavaScript code:
$("#tblextendedresults tbody").prepend("<br>")
$.each(extendedResults, function(i) {
$("#tblextendedresults tbody").append("<tr><td>" + extendedResults[i]["question"] + "</td><td>" + extendedResults[i]["your_answer"] + "</td><td>" + extendedResults[i]["correct"] + "</td></tr>")
if (extendedResults[i]["correct"] == "true") {
$(this).css("color", "green");
}
else {
$(this).css("color", "red");
}
})
Related HTML code:
<table id="tblextendedresults">
<thead>
<th>Question</th>
<th>Your answer</th>
<th>Correct?</th>
</thead>
<br>
<tbody></tbody>
</table>
Also 'extendedResults' is an array that each question and chosen answer are pushed to. Any help would be appreciated. Thanks!