Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

back button (working one) #16

Merged
merged 3 commits into from
Apr 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 86 additions & 61 deletions quiz.html
Original file line number Diff line number Diff line change
@@ -1,61 +1,86 @@
<head>
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:400,700" rel="stylesheet">
<link href='style.css' rel='stylesheet' type='text/css'>
<title>8values Quiz</title>
<link rel="icon" type="x-icon" href="icon.png">
<link rel="shortcut icon" type="x-icon" href="icon.png">
<meta charset="utf-8">
</head>
<body>
<script type="application/javascript"
src="questions.js">
</script>
<h1>8values</h1>
<hr>
<h2 style="text-align:center;" id="question-number">Loading...</h2>
<p class="question" id="question-text"></p>
<button class="button" onclick="next_question( 1.0)" style="background-color: #1b5e20;">Strongly Agree</button> <br>
<button class="button" onclick="next_question( 0.5)" style="background-color: #4caf50;">Agree</button> <br>
<button class="button" onclick="next_question( 0.0)" style="background-color: #bbbbbb;">Neutral/Unsure</button> <br>
<button class="button" onclick="next_question(-0.5)" style="background-color: #f44336;">Disagree</button> <br>
<button class="button" onclick="next_question(-1.0)" style="background-color: #b71c1c;">Strongly Disagree</button> <br>

<script>
var max_econ, max_dipl, max_govt, max_scty; // Max possible scores
max_econ = max_dipl = max_govt = max_scty = 0
var econ, dipl, govt, scty; // User's scores
econ = dipl = govt = scty = 0
var qn = 0; // Question number
document.getElementById("question-text").innerHTML=questions[qn].question
document.getElementById("question-number").innerHTML="Question " + (qn + 1) + " of " + (questions.length)
for (var i = 0; i < questions.length; i++) {
max_econ += Math.abs(questions[i].effect.econ)
max_dipl += Math.abs(questions[i].effect.dipl)
max_govt += Math.abs(questions[i].effect.govt)
max_scty += Math.abs(questions[i].effect.scty)
}
function next_question(mult) {
econ += mult*questions[qn].effect.econ
dipl += mult*questions[qn].effect.dipl
govt += mult*questions[qn].effect.govt
scty += mult*questions[qn].effect.scty
qn++
if (qn < questions.length) {
document.getElementById("question-text").innerHTML=questions[qn].question
document.getElementById("question-number").innerHTML="Question " + (qn + 1) + " of " + (questions.length)
} else {
results()
}
}
function calc_score(score,max) {
return (100*(max+score)/(2*max)).toFixed(1)
}
function results() {
location.href = `results.html`
+ `?e=${calc_score(econ,max_econ)}`
+ `&d=${calc_score(dipl,max_dipl)}`
+ `&g=${calc_score(govt,max_govt)}`
+ `&s=${calc_score(scty,max_scty)}`
}
</script>
</body>
<head>
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:400,700" rel="stylesheet">
<link href='style.css' rel='stylesheet' type='text/css'>
<title>8values Quiz</title>
<link rel="icon" type="x-icon" href="icon.png">
<link rel="shortcut icon" type="x-icon" href="icon.png">
<meta charset="utf-8">
</head>
<body>
<script type="application/javascript"
src="questions.js">
</script>
<h1>8values</h1>
<hr>
<button class="menubutton" onclick="prev_question" id="back_button">Back</button><br>
<h2 style="text-align:center;" id="question-number">Loading...</h2>
<p class="question" id="question-text"></p>
<button class="button" onclick="next_question( 1.0)" style="background-color: #1b5e20;">Strongly Agree</button> <br>
<button class="button" onclick="next_question( 0.5)" style="background-color: #4caf50;">Agree</button> <br>
<button class="button" onclick="next_question( 0.0)" style="background-color: #bbbbbb;">Neutral/Unsure</button> <br>
<button class="button" onclick="next_question(-0.5)" style="background-color: #f44336;">Disagree</button> <br>
<button class="button" onclick="next_question(-1.0)" style="background-color: #b71c1c;">Strongly Disagree</button> <br>

<script>
var max_econ, max_dipl, max_govt, max_scty; // Max possible scores
max_econ = max_dipl = max_govt = max_scty = 0;
var econ, dipl, govt, scty; // User's scores
econ = dipl = govt = scty = 0;
var qn = 0; // Question number
var prev_answer = -20;
init_question();
for (var i = 0; i < questions.length; i++) {
max_econ += Math.abs(questions[i].effect.econ)
max_dipl += Math.abs(questions[i].effect.dipl)
max_govt += Math.abs(questions[i].effect.govt)
max_scty += Math.abs(questions[i].effect.scty)
}
function init_question() {
document.getElementById("question-text").innerHTML = questions[qn].question;
document.getElementById("question-number").innerHTML = "Question " + (qn + 1) + " of " + (questions.length);
if (prev_answer == -20) {
document.getElementById("back_button").style.visibility = 'hidden';
} else {
document.getElementById("back_button").style.visibility = 'visible';
}

}

function next_question(mult) {
econ += mult*questions[qn].effect.econ
dipl += mult*questions[qn].effect.dipl
govt += mult*questions[qn].effect.govt
scty += mult*questions[qn].effect.scty
qn++;
prev_answer = mult;
if (qn < questions.length) {
init_question();
} else {
results();
}
}
function prev_question() {
if (prev_answer == -20) {
return;
}
qn--;
econ -= prev_answer * questions[qn].effect.econ;
dipl -= prev_answer * questions[qn].effect.dipl;
govt -= prev_answer * questions[qn].effect.govt;
scty -= prev_answer * questions[qn].effect.scty;
prev_answer = -20;
init_question();

}
function calc_score(score,max) {
return (100*(max+score)/(2*max)).toFixed(1)
}
function results() {
location.href = `results.html`
+ `?e=${calc_score(econ,max_econ)}`
+ `&d=${calc_score(dipl,max_dipl)}`
+ `&g=${calc_score(govt,max_govt)}`
+ `&s=${calc_score(scty,max_scty)}`
}
</script>
</body>
16 changes: 16 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ img.center {
margin: 0 auto;
cursor: pointer;
}
.menubutton {
background-color: #bbbbbb;
font-family: 'Montserrat', sans-serif;
border: none;
border-radius: 8pt;
color: #333333;
padding: 8pt;
width: 10%;
min-width: 100pt;
text-align: center;
text-decoration: none;
display: block;
font-size: 18pt;
margin: 0 auto;
cursor: pointer;
}
div.axis {
width: 100%;
display: flex;
Expand Down