Last active
February 27, 2019 18:21
-
-
Save robinweser/6389222f1190e3923a20946e97c3c774 to your computer and use it in GitHub Desktop.
Fernuni Psychology Point Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getQuestionPoints(number, highlight) { | |
var question = document.getElementsByClassName("content")[number - 1]; | |
var rightAnswer = question.getElementsByClassName("rightanswer")[0].innerText; | |
var answers = question.getElementsByClassName("answer")[0]; | |
var answerMap = {}; | |
for (var i = 0; i < answers.children.length; ++i) { | |
var child = answers.children[i]; | |
answerMap[child.children[1].innerText] = child.children[0].checked; | |
} | |
return Object.keys(answerMap).reduce(function(points, answer, index) { | |
var isRightAnswer = rightAnswer.indexOf(answer.substring(3)) !== -1; | |
if (isRightAnswer === answerMap[answer]) { | |
points += 1; | |
} | |
if (highlight && isRightAnswer && !answerMap[answer]) { | |
var label = answers.children[index].children[1] | |
label.style.color = "red"; | |
for (var i = 0; i < label.children.length; ++i) { | |
label.children[i].style.color = "red" | |
} | |
} | |
return points; | |
}, 0); | |
} | |
function getTotalPoints(count, highlight) { | |
var total = 0; | |
for (var i = 1; i <= count; ++i) { | |
total += getQuestionPoints(i, highlight); | |
} | |
return total; | |
} | |
function run(highlight) { | |
var count = document.getElementsByClassName("answer").length; | |
var points = getTotalPoints(count, highlight); | |
var totalPoints = count * 5; | |
alert( | |
"Punkte: " + | |
points + | |
"/" + | |
totalPoints + | |
"\nBewertung: " + | |
(points / (count / 2)).toLocaleString("de") + | |
"/10 (" + | |
(points / (count / 20)).toLocaleString("de") + | |
"%)" | |
); | |
} | |
run(true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment