This repository has been archived by the owner on Jun 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
396059a
commit 80dc4ea
Showing
5 changed files
with
180 additions
and
205 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
function calculateScore() { | ||
|
||
var questionCount = 11; | ||
|
||
// questions with only moderate answers | ||
var moderateAnswers = 4; | ||
|
||
// questions with strong answers | ||
var strongAnswers = 7; | ||
|
||
var moderateWeight = 1.0; | ||
var strongWeight = 2.0; | ||
|
||
// adds the submitted answers to the results URL, useful for feedback from test takers | ||
var answers = ''; | ||
var right = 0.0; | ||
var left = 0.0; | ||
var lib = 0.0; | ||
|
||
for (let q = 1; q <= questionCount; q++) { | ||
|
||
let s = document.getElementById("s" + q); | ||
|
||
if (s.options[s.selectedIndex].value === "Neutral") { | ||
answers += 'n'; | ||
} else if (s.options[s.selectedIndex].value === "Left1") { | ||
left += moderateWeight; | ||
answers += 'l1'; | ||
} else if (s.options[s.selectedIndex].value === "Left2") { | ||
left += strongWeight; | ||
answers += 'l2'; | ||
} else if (s.options[s.selectedIndex].value === "Lib1") { | ||
lib += moderateWeight; | ||
answers += 'i1'; | ||
} else if (s.options[s.selectedIndex].value === "Lib2") { | ||
lib += strongWeight; | ||
answers += 'i2'; | ||
} else if (s.options[s.selectedIndex].value === "Right1") { | ||
right += moderateWeight; | ||
answers += 'r1'; | ||
} else if (s.options[s.selectedIndex].value === "Right2") { | ||
right += strongWeight; | ||
answers += 'r2'; | ||
} | ||
} | ||
|
||
// divide by the points in total for each axis (sum of the max amount of points for each question) | ||
right /= (moderateAnswers * moderateWeight) + (strongAnswers * strongWeight); | ||
left /= (moderateAnswers * moderateWeight) + (strongAnswers * strongWeight); | ||
lib /= (moderateAnswers * moderateWeight) + (strongAnswers * strongWeight); | ||
|
||
// convert to a number between 0 and 10 rounded to the nearest hundredth | ||
right = Math.round(right * 1000) / 100; | ||
left = Math.round(left * 1000) / 100; | ||
lib = Math.round(lib * 1000) / 100; | ||
|
||
window.location.href = "results.html?left=" + left + "&right=" + right + "&lib=" + lib + "&answers=" + answers; | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
function drawResults() { | ||
|
||
let parser = document.createElement('a'); | ||
parser.href = window.location.href; | ||
let vars = parser.search.substring(1).split('&'); | ||
for (let i = 0; i < vars.length; i++) { | ||
let thevar = vars[i].split('='); | ||
if (thevar[0] === "left") { | ||
document.getElementById("left-score").innerHTML = parseFloat(thevar[1]); | ||
var left = parseFloat(thevar[1]) / 10; | ||
} | ||
if (thevar[0] === "right") { | ||
document.getElementById("right-score").innerHTML = parseFloat(thevar[1]); | ||
var right = parseFloat(thevar[1]) / 10; | ||
} | ||
if (thevar[0] === "lib") { | ||
document.getElementById("lib-score").innerHTML = parseFloat(thevar[1]); | ||
var lib = parseFloat(thevar[1]) / 10; | ||
} | ||
} | ||
|
||
let canvas = document.getElementById("canvas").getContext('2d'); | ||
|
||
// stops the edge of the canvas from cutting off parts of the image | ||
let shift = 15; | ||
|
||
canvas.lineWidth = 2; | ||
canvas.beginPath(); | ||
canvas.moveTo(180 + shift, 311.769 + shift); | ||
canvas.lineTo(360 + shift, 415.692 + shift); | ||
canvas.lineTo(540 + shift, 311.769 + shift); | ||
canvas.lineTo(360 + shift, 0 + shift); | ||
canvas.lineTo(180 + shift, 311.769 + shift); | ||
canvas.fillStyle = '#ffeeaa'; | ||
canvas.fill(); | ||
canvas.stroke(); | ||
canvas.beginPath(); | ||
canvas.moveTo(180 + shift, 311.769 + shift); | ||
canvas.lineTo(360 + shift, 415.692 + shift); | ||
canvas.lineTo(360 + shift, 623.538 + shift); | ||
canvas.lineTo(0 + shift, 623.538 + shift); | ||
canvas.lineTo(180 + shift, 311.769 + shift); | ||
canvas.fillStyle = '#ffaaaa'; | ||
canvas.fill(); | ||
canvas.stroke(); | ||
canvas.beginPath(); | ||
canvas.moveTo(360 + shift, 415.692 + shift); | ||
canvas.lineTo(540 + shift, 311.769 + shift); | ||
canvas.lineTo(720 + shift, 623.538 + shift); | ||
canvas.lineTo(360+ shift, 623.538 + shift); | ||
canvas.lineTo(360 + shift, 415.692 + shift); | ||
canvas.fillStyle = '#aaeeff'; | ||
canvas.fill(); | ||
canvas.stroke(); | ||
|
||
canvas.beginPath(); | ||
canvas.arc(360 - (left * 360) + (right * 360) + shift, 415.692 + (left * 207.846) + (right * 207.846) - (lib * 415.692) + shift, 12, 0, Math.PI * 2); | ||
canvas.fillStyle = 'red'; | ||
canvas.fill(); | ||
canvas.stroke(); | ||
} |
Oops, something went wrong.