I am using Surveyjs to set up a quiz but have this problem on the completed page:
When using the variable correctAnswers to show the number of correct answers on the completed page it does not work on completedBeforeHTML – but it works on completedHTML.
I set the property completedBeforeHTML like this: (as described in the docs https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#completedBeforeHtml)
“Thank you for running the quiz. You had {correctAnswers} correct answers. “
I expected the {correctAnswers} to show number of correct answers on completedBeforeHTML but it just shows 0.
2
Ensure that you define the survey.data
and set an existing user response to a survey.
survey.data = {
"username": "Jane",
"civilwar": "1861-1865",
"libertyordeath": "James Madison",
"magnacarta": "The foundation of the British parliamentary system"
};
I created this demo for your reference: View Plunker. You can run this quiz, and then re-run it to see that the Complete page appears as expected and shows the number of correct answers.
const json = {
"cookieName": "quiz-survey",
...
"completedBeforeHtml": "<h3>You got {correctAnswers} correct answers</h3>",
"completedHtml": "<h3>You got {correctAnswers} correct answers</h3>",
//...