// 270812 rewritten displayquestion // 140812 - quizcode.js - quiz handling section // using copy of questions array, selects one at a time and displays it // includes sound code, slideup/down jquery animation, getquestion no., shakeup(), display question // doesn't include correct fn //----------------------- // 050810 - Disable enter key - www.webcheatsheet.com method function stopRKey(evt) { var evt = (evt) ? evt : ((event) ? event : null); var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if (evt.keyCode == 13) {return false;} } document.onkeypress = stopRKey; answer=""; correctanswer=0; // if answer correct qloaded=1; // stop answering same question twice distractornum=0; // 020612 initialise global for no. of distractors 4 or 5 score=0; spinwin=0; if(typeof gametitle!='string') {gametitle=''} // 150211 - use gametitle if available function restart(){ q=new Array(); // initialise q array document.getElementById('questionbutton').style.visibility='visible'; choice=''; //initialise answer letter to null. document.getElementById('qdiv').style.display='none'; // hide to start document.getElementById('stem').style.visibility='hidden'; } function getaquestion(){ if(q.length-1<1) // if all questions are used, start again {q=questions.slice(0);} // get a questionnumber at random from q questionnum=Math.floor(Math.random()*(q.length-1))+1; //add 1 cos q[0] is empty qloaded=1; ///new question $("#qdiv").slideUp("normal",displayquestion); // slide and display new question $("#qdiv").slideDown("normal"); } function displayquestion(){ testsplit=q[questionnum].split('~'); // split question into array elements // 020612 4/5 distractors if ((testsplit[5]=='A')||(testsplit[5]=='B')|| (testsplit[5]=='C')||(testsplit[5]=='D')) {distractornum=4;// only 4 distractors, hide 5th document.getElementById('responseE').style.display='none'; } else {distractornum=5; document.getElementById('responseE').style.display='block'; } shakeup(); // randomise distractor locations // find true question no. by matching question contents to original array errorflag=1; for (var i=1;i<=questions.length-1;i++) {if(q[questionnum]==questions[i]) {errorflag=0; realquestionnumber=i; // the actual question number in questions array } } linkq=''; // assign no links to linkq // load question into cells document.getElementById('stem').innerHTML='Question '+realquestionnumber+": "+testsplit[0]; document.getElementById('responseAlink').innerHTML='A) '+testsplit[1]; document.getElementById('responseBlink').innerHTML='B) '+testsplit[2]; document.getElementById('responseClink').innerHTML='C) '+testsplit[3]; document.getElementById('responseDlink').innerHTML='D) '+testsplit[4]; if (distractornum==5) {document.getElementById('responseElink').innerHTML='E) '+testsplit[5];} answer=testsplit[distractornum+1]; difficulty=testsplit[distractornum+2]; gamelevel=testsplit[distractornum+3]; hint=testsplit[distractornum+4]; linkq=testsplit[distractornum+5] q.splice(questionnum,1); // remove current question from array resetquestion(); } function resetquestion(){ choice=''; //initialise answer letter to null. // hide 'questionbutton' and 'bankgold' button // document.getElementById('questionbutton').style.visibility='hidden'; document.getElementById('questionbutton').style.display='none'; // make questions visible and style distractors document.getElementById('stem').style.visibility='visible'; } function shakeup(){ // function by to shuffle the answers in some QGM games // input array testsplit[], [0]=Question, [1]-[4]=possible answers, [5]=key A-E to correct answer var abcde="ABCDE"; var i; // need to declare this to protect other counters for(i=1; i<=distractornum; i++){ var aa=testsplit[distractornum+1]; //the original answer position var x=aa.charCodeAt(0)-64; // convert ASCII code for answer into number in range 1-4 var newplace=Math.ceil(Math.random()*distractornum); var temp=testsplit[newplace]; testsplit[newplace]=testsplit[i]; testsplit[i]=temp; //swap index with newplace if(i==x){testsplit[distractornum+1]=abcde.substring(newplace-1,newplace);} // if moving the answer, correct the answer flag if(newplace==x){testsplit[distractornum+1]=abcde.substring(i-1,i);} // if displacing the answer, adjust the answer flag } }