summaryrefslogtreecommitdiff
path: root/modules/zelfoverhoor/qs.js
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-11-22 21:23:14 +0100
committertomsmeding <tom.smeding@gmail.com>2017-11-22 22:23:51 +0100
commit32523cdcd9eaa4ad9363d79ebe82d5de4b852676 (patch)
tree88b27b82007047e6923c608cc44ca38dcd0e125a /modules/zelfoverhoor/qs.js
parent58d635e0c88ea5428072f7901417908f455b93ec (diff)
Add module 'zelfoverhoor'
Beta stage
Diffstat (limited to 'modules/zelfoverhoor/qs.js')
-rw-r--r--modules/zelfoverhoor/qs.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/modules/zelfoverhoor/qs.js b/modules/zelfoverhoor/qs.js
new file mode 100644
index 0000000..cc68af9
--- /dev/null
+++ b/modules/zelfoverhoor/qs.js
@@ -0,0 +1,76 @@
+var setname=questionset.name;
+var setdescription=questionset.description;
+var questions=questionset.questions;
+
+var currentidx=0;
+var numcorrect=0;
+
+function clearElement(el){
+ while(el.lastChild)el.removeChild(el.lastChild);
+}
+
+function shuffle(a){
+ var j,v,i;
+ for(var i=a.length-1;i>0;i--){
+ j=Math.floor(Math.random()*(i+1));
+ v=a[i]; a[i]=a[j]; a[j]=v;
+ }
+}
+
+function startQuiz(){
+ currentidx=0;
+ numcorrect=0;
+ showCurrent();
+}
+
+function showCurrent(){
+ document.getElementById("qcontainer").classList.remove("invisible");
+ document.getElementById("rescontainer").classList.add("invisible");
+ document.getElementById("answercontainer").classList.add("invisible");
+ document.getElementById("showAnswerButton").classList.remove("invisible");
+
+ var qdiv=document.getElementById("question");
+ clearElement(qdiv);
+ qdiv.appendChild(document.createTextNode(questions[currentidx].q));
+}
+
+function showAnswer(){
+ document.getElementById("answercontainer").classList.remove("invisible");
+ document.getElementById("showAnswerButton").classList.add("invisible");
+
+ var adiv=document.getElementById("answer");
+ clearElement(adiv);
+ adiv.appendChild(document.createTextNode(questions[currentidx].a));
+}
+
+function finishQuiz(){
+ document.getElementById("qcontainer").classList.add("invisible");
+ document.getElementById("rescontainer").classList.remove("invisible");
+ document.getElementById("numcorrect").innerHTML=numcorrect;
+ document.getElementById("numtotal").innerHTML=questions.length;
+ if(numcorrect==questions.length){
+ document.getElementById("allcorrectp").classList.remove("invisible");
+ } else {
+ document.getElementById("allcorrectp").classList.add("invisible");
+ }
+}
+
+function advance(corr){
+ if(corr)numcorrect++;
+ currentidx++;
+ if(currentidx<questions.length){
+ showCurrent();
+ } else {
+ finishQuiz();
+ }
+}
+
+window.addEventListener("load",function(){
+ document.getElementById("qsetname").appendChild(document.createTextNode(setname));
+ document.getElementById("qsetdescr").appendChild(document.createTextNode(setdescription));
+ if(questions.length==0){
+ alert("Deze lijst heeft geen vragen, dus er kan weinig overhoord worden, eerlijk gezegd...");
+ return;
+ }
+ startQuiz();
+});