【发布时间】:2011-06-07 22:01:15
【问题描述】:
比this SO question 更复杂,我在听听你对测验分数计算的想法,这是我的场景:
我有 X 个选项(任何 HTML 元素都可以作为选项提供),用户可以从中选择选项组合作为他们的答案。到目前为止,我试图通过以下方式保持通用性:
- 维护一组正确答案
- 按索引条目将所选答案与正确答案进行比较
- 如果找到正确的匹配项,则将分数加 1
- 单独处理单选选项问题,因为它们始终是真/假
下面的示例:假设选择了 6 个干扰节点,其中节点 0、1、2 是正确的。 'selectedAnswers' 是一个数组,其中包含任何选定干扰项的索引值。 'correctAnswers' 是一组预先确定的正确干扰指标。
// Each option is worth a standardised amount, unless custom weightings
// are required - not implemented.
var weighting = (100/this.distractors.length);
var score = 0;
for(var i=0;i<this.selectedAnswers.length;i++){
if( ut.arrayContains(this.correctAnswer, this.selectedAnswers[i]) ){
// Correct answer found, increase total
score += weighting*2;
} else {
if( yd.hasClass(this.distractors[ this.selectedAnswers[i] ], SELECTED_CLASS) ){
// Penalise the score by a double weightingfor selecting an incorrect answer
score -= weighting*2;
//log('reducing score by 2 weightings');
} else {
// Penalise the score by a single weighting for leaving an incorrect node unselected
score -= weighting;
//log('reducing score by 1 weighting');
}
}
}
this.score( (score<0)? 0 : Math.ceil(score) );
当一个选项未被选中时降低分数似乎违反直觉,如果它被选中的话会不正确 - 但它似乎让我更接近我所追求的逻辑。事实上,提供的分数似乎相当准确,直到您考虑选择越来越多的错误选项和越来越少的正确选项的场景。
如果必须的话,我会从我们的构建中制作一个演示并投入使用,请告诉我!
编辑: 呃,对不起,我想太多了,问题是:
我如何提供准确的百分比分数,同时考虑不正确和正确的答案?
【问题讨论】:
-
嗯,对 'yd' 和 'ut' 的引用是 YUI 的便捷快捷方式。
-
如果现在这是一个可行的问题,请随意删除 -1 - 它会阻止实际收到答案。
标签: javascript math logic