Question T9714
Visible to All Users

How to show that the answer is correct?

created 3 years ago (modified 3 years ago)

Can you use your library to create and then automatically grade a test? The user would have to indicate the right answers to questions somehow.

Answers approved by surveyjs Support

created 3 years ago

Hello Alan,
You can use two events onValueChanged to make a question read-only and modify the title and "onTextMarkdown" to add css rules to your indicators.
Here is the code and working example:

JavaScript
survey.onValueChanged.add((sender, options) => {   const q = options.question;   if(!q) return;   q.readOnly = true;   q.title += q.isAnswerCorrect() ? "*Correct*" : "*Incorrect*"; }); survey.onTextMarkdown.add((sender, options) => {   debugger;   if(options.name !== "title" || !options.text) return;   if(options.text.indexOf("*Correct*") > -1) {     options.html = options.text.replace("*Correct*""<span class='answer-correct'>Correct</span>");   }   if(options.text.indexOf("*Incorrect*") > -1) {     options.html = options.text.replace("*Incorrect*""<span class='answer-incorrect'>Incorrect</span>");   } });
    Comments (2)

      Ok, but how would the user designing the survey provide the correct answer to begin with? We need to know what the correct answer for each question is before we can grade the test.

        Hello Alan,
        You can see in my example, there is "correctAnswer" property. You can find this property in the "Data" category.

        Thank you,
        Andrew
        SurveyJS Team