
// JSON example
var candidates = [ {
  "name": "Ellie Phanta",
  "party": "Republican",
  "stances" : [-2,-2]
  },
  {
  "name": "Jack Bass",
  "party": "Democrat",
  "stances" : [-2,-2]
  },
  {
  "name": "Paul Stanton",
  "party": "Libertarian",
  "stances" : [2,2]
  }
 ];

Questions = [ 
  {
  "Question" : "Should goods and services be provided by force?",
  "Responses" : [
    ["Absolutely",-2],
    ["Yes", -1],
    ["Maybe", 0],
    ["No", 1],
    ["Never", 2]]
},
   {
  "Question" : "Without government, Who will build the roads?",
  "Responses" : [
    ["No one at all",-2],
    ["Shady people you can't trust", -1],
    ["Someone might maybe possibly", 0],
    ["Construction companies", 1],
    ["Where we're going, we won't need roads.", 2]]
},            
];

Imports = [["Could not care less",1],["Don't care",2],["Might care",3],["Care",4],["Care a lot",5]];

responses = [];
importance = [];
results = [];

for (i = 0; i < Questions.length; i++) {
 responses.push(0);
 importance.push(0);

}

  for (j = 0; j < Candidites.length; j++) {
    arr = [];
    for (i = 0; i < Questions.length; i++) {    
      arr.push(0);
    }
    results.push(arr);
  }

function loadQuestions() {
  var chunk = '';
  for (i = 0; i < Questions.length; i++) {
    chunk += '<div id="q' + i + '>'; 
    chunk += '<p class="question">' + Questions[i].Question + '</p>';
    chunk += '<p class="answers">';
    for (j = 0; j < Questions[i].Responses.length; j++) {
     var qr = Questions[i].Responses[j];
     chunk += '<button onclick="tally(' + i + ',' + qr[1] + ')">' + qr[0] + '</button>';
    }
    chunk += '</p>';
    chunk += '<p class="importance">';
    for (k = 0; k < Imports.length; k++) {
     chunk += '<button onclick="tallyImports(' + i + ',' + Imports[k][1] + ')">' + Imports[k][0] + '</button>';
    }    
    chunk += '</p></div>';
  }
  chunk += '<p><button onclick="compareCandidates()">Calculate</button></p>';
  document.getElementById("questionArea").innerHTML = chunk;
};

function tally(questionNumber,response) {
  //qId = 'q' + questionNumber;
  responses[questionNumber] = response;
  document.getElementById("test").innerHTML = responses;
  //document.getElementById(qId).innerHTML = 'Response Recorded';
};

function tallyImports(questionNumber,response) {
  //qId = 'q' + questionNumber;
  importance[questionNumber] = response;
  document.getElementById("test2").innerHTML = importance;
  //document.getElementById(qId).innerHTML = 'Response Recorded';
};

function compareToCandidates() {
  for (i = 0; i < candidates.length; i++) {
    for (j = 0; j < Questions.length; j++) {
      results[i][j] = Math.abs(responses[j]-candidates[i].stances[j])*importance[j];
    }
  }
  document.getElementById("test").innerHTML = results;
};

loadQuestions();

@@ -752,17 +752,16 @@
 %22, 2%5D%5D%0A%7D
-,
         
@@ -960,16 +960,17 @@
  i++) %7B%0A
+ 
  respons
@@ -981,16 +981,17 @@
 ush(0);%0A
+ 
  importa
@@ -1007,14 +1007,11 @@
 0);%0A
-%0A
 %7D%0A%0A
-  
 for 
@@ -1026,15 +1026,15 @@
 j %3C 
-C
+c
 andid
-i
+a
 tes.
@@ -1054,119 +1054,33 @@
 %7B%0A  
-  arr = %5B%5D;%0A    for (i = 0; i %3C Questions.length; i++) %7B    %0A      arr.push(0);%0A    %7D%0A    results.push(arr
+results.push(responses
 );%0A
-  
 %7D%0A%0Af
@@ -2513,24 +2513,53 @@
 gth; j++) %7B%0A
+      max = 5*importance%5Bj%5D;%0A
       result
@@ -2567,16 +2567,23 @@
 %5Bi%5D%5Bj%5D =
+ (max -
  Math.ab
@@ -2596,17 +2596,19 @@
 onses%5Bj%5D
--
+ - 
 candidat
@@ -2624,17 +2624,19 @@
 nces%5Bj%5D)
-*
+ * 
 importan
@@ -2636,24 +2636,29 @@
 mportance%5Bj%5D
+)/max
 ;%0A    %7D%0A  %7D%0A
@@ -2680,32 +2680,33 @@
 lementById(%22test
+3
 %22).innerHTML = r

Update wme.js