After a user has completed the quiz, what would be the best manner to show both the user answer and correct answer in a quiz. And can some colors be set. Perhaps red if user answer is wrong? Thanks
Showing User Answer and Correct Answer in display mode
Answers approved by surveyjs Support
Hello,
I would suggest the following code to show results of your Quiz:
JavaScriptsurvey.mode = "display";
survey.questionsOnPageMode = "singlePage";
survey.showNavigationButtons = "none";
survey.showProgressBar = "off";
survey.showTimerPanel = "none";
survey
.onAfterRenderQuestion
.add(function (survey, options) {
var span = document.createElement("span");
var isCorrect = options.question.isAnswerCorrect();
span.innerHTML = isCorrect ? "Correct" : "Incorrect";
span.style.color = isCorrect ? "green": "red";
var header = options
.htmlElement
.querySelector("h5");
header.appendChild(span);
});
Here is the example.
Thank you,
Andrew
SurveyJS Team
Show previous comments
(1)
AT
5 years ago
You can call survey.render(); function at the end of onClick event.
If response is your data, then you can call survey.data = _response;
Thank you,
Andrew
SurveyJS Team