Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved levelRanges into defaults #88

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions js/slickQuiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
completionResponseMessaging: false,
displayQuestionCount: true, // Deprecate?
displayQuestionNumber: true, // Deprecate?
levelRanges: {
4: {min: 0.81, max: 1},
3: {min: 0.61, max: 0.8},
2: {min: 0.41, max: 0.6},
1: {min: 0.21, max: 0.4},
0: {min: 0, max: 0.2}
},
animationCallbacks: { // only for the methods that have jQuery animations offering callback
setupQuiz: function () {},
startQuiz: function () {},
Expand Down Expand Up @@ -609,15 +616,14 @@
if (plugin.config.disableRanking) {
$(_quizLevel).remove()
} else {
var levels = [
quizValues.info.level1, // 80-100%
quizValues.info.level2, // 60-79%
quizValues.info.level3, // 40-59%
quizValues.info.level4, // 20-39%
quizValues.info.level5 // 0-19%
],
levelRank = plugin.method.calculateLevel(score),
levelText = $.isNumeric(levelRank) ? levels[levelRank] : '';
var levels = [];

$.each(quizValues.info, function(levelNumber, levelText){
levels.push(levelText);
});

var levelRank = plugin.method.calculateLevel(score),
levelText = $.isNumeric(levelRank) ? levels[levelRank] : '';

$(_quizLevel + ' span').html(levelText);
$(_quizLevel).addClass('level' + levelRank);
Expand Down Expand Up @@ -658,19 +664,14 @@
// Calculates knowledge level based on number of correct answers
calculateLevel: function(correctAnswers) {
var percent = (correctAnswers / questionCount).toFixed(2),
level = null;

if (plugin.method.inRange(0, 0.20, percent)) {
level = 4;
} else if (plugin.method.inRange(0.21, 0.40, percent)) {
level = 3;
} else if (plugin.method.inRange(0.41, 0.60, percent)) {
level = 2;
} else if (plugin.method.inRange(0.61, 0.80, percent)) {
level = 1;
} else if (plugin.method.inRange(0.81, 1.00, percent)) {
level = 0;
}
level = null;

$.each(plugin.config.levelRanges, function(grade, range){
if(plugin.method.inRange(range.min, range.max, percent)){
level = grade;
return;
}
});

return level;
},
Expand Down