Following is the JSON using surveyjs to build a survey with a question with 4 options and each option has a value (score).
Working example here: https://embed.plnkr.co/20U6sdQpOiTxd5ps83dT/
Here is what is required:
A. I need multiple questions here (25). There is only 1 now.
B. If you answered 4 or more questions 'Unknown' subtract 20 points from total score.
C. Result (Text based) based on score:
75-100 Total Score: Our Service Not Required
50-75 Total Score: You Need An Assessment
50 Total Score: Our Service Is Required
Here is the JSON code:
Survey
.StylesManager
.applyTheme("default");
Survey
.JsonObject
.metaData
.addProperty("question", {name: "score:number"});
Survey.JsonObject.metaData.addProperty("itemvalue", {name: "score:number"});
var json = {
questions: [
{
"type": "boolean",
"name": "myboolean",
"label": "ten",
"score": 10
},
{
type: "radiogroup",
name: "myradiogroup",
title: "Do you have multiple business applications in use by your various departments in the daily operation of the company?",
colCount: 4,
choices: [
{
value: "Yes",
score: 4
},
{
value: "No",
score: 4
},
{
value: "Unknown",
score: 0
},
{
value: "NA",
score: 0
}
]
}
]
};
window.survey = new Survey.Model(json);
survey
.onComplete
.add(function (survey) {
var totalScore = 0;
var data = survey.data;
Object.keys(data).forEach(function(qName) {
var question = survey.getQuestionByName(qName);
var qValue = data[qName];
if (question.choices) {
question.choices.forEach(function(choice) {
if (choice.value === qValue) {
totalScore += +choice.score;
}
});
} else {
totalScore += +question.score;
}
});
document
.querySelector('#surveyResult')
.innerHTML = "total score: " + JSON.stringify(totalScore);
});
$("#surveyElement").Survey({model: survey});
question from:
https://stackoverflow.com/questions/65931079/survey-with-numeric-score-to-each-option-custom-output-based-on-score 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…