Widget:WJG Sandbox: Difference between revisions

Jump to navigation Jump to search
No edit summary
No edit summary
Line 981: Line 981:
$("#details").slideToggle("slow");}
$("#details").slideToggle("slow");}


function convolve_bernouli(qprobs){
//takes in an array of probabilities of guessing questions correct
for (var counter = 0; counter < qprobs.length; counter++) {
//if the loop is in the first iteration, then initialize the array
if (counter==0){
    var pdfArray=[1-qprobs[0],qprobs[0]];
}else{
    //initialize new Array for pdfs
    var newpdfArray= [];
  for (var i = 0; i < pdfArray.length+1; i+=1) {
        newpdfArray[i]=0;
    }
    //multiply by ones first
  for (var i = 0; i < pdfArray.length; i+=1) {
        newpdfArray[i+1]+=pdfArray[i]*qprobs[counter]; //probability of adding a success
        newpdfArray[i]+=pdfArray[i]*(1-qprobs[counter]);
    }
   
    pdfArray=newpdfArray;
}
}
console.log(pdfArray);
return(pdfArray);
}//ends convolve_bernouli


function endExam(event) {
function endExam(event) {
Line 993: Line 1,018:
datas += "<br />You answered " + event.data.answeredRight + " out of " + event.data.examQuestions.length + " correctly.<br /> Your percentage score is: ";
datas += "<br />You answered " + event.data.answeredRight + " out of " + event.data.examQuestions.length + " correctly.<br /> Your percentage score is: ";
var percent = (event.data.answeredRight / event.data.examQuestions.length) * 100;
var percent = (event.data.answeredRight / event.data.examQuestions.length) * 100;
testlength=event.data.examQuestions.length;
var question_probs=[];
for (var j = 0; j < testlength; j+=1){
    question_probs[j]=Math.random();
}
qdist=convolve_bernouli(question_probs);
datas += percent + "%<br /><br />Click the Navigation Buttons on the left to review the questions you answered.";
datas += percent + "%<br /><br />Click the Navigation Buttons on the left to review the questions you answered.";
var api = new mw.Api();
var api = new mw.Api();

Revision as of 22:38, 22 May 2014