Question T4196
Visible to All Users

Showing User Answer and Correct Answer in display mode

created 5 years ago

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

Answers approved by surveyjs Support

created 5 years ago

Hello,
I would suggest the following code to show results of your Quiz:

JavaScript
survey.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)

      You are welcome!

      Andrew
      SurveyJS Team

        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

          That worked!!!