Add metadata to individual answers
we achieve this by making Answer a class instead of an integer literal
This commit is contained in:
parent
b3d5aea32d
commit
f52065dee0
|
|
@ -36,3 +36,12 @@ class Question {
|
|||
}
|
||||
};
|
||||
};
|
||||
|
||||
class Answer {
|
||||
answer = 0; // will take values from 0 to 3
|
||||
last_changed = 0;
|
||||
constructor(answer = 0, last_changed = 0){
|
||||
this.answer = answer;
|
||||
this.last_changed = last_changed;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
15
src/main.js
15
src/main.js
|
|
@ -15,8 +15,8 @@ function prepare(){
|
|||
};
|
||||
|
||||
function startUp(){
|
||||
my.answers = questions.map(function () { return 0; });
|
||||
their.answers = questions.map(function () { return 0; });
|
||||
my.answers = questions.map(function () { return new Answer(); });
|
||||
their.answers = questions.map(function () { return new Answer(); });
|
||||
my.last_changed=0;
|
||||
last_sent=0;
|
||||
their.last_changed=0;
|
||||
|
|
@ -48,12 +48,12 @@ function updateHTML(){
|
|||
let y = x + questions[x].corresponds_to;
|
||||
console.log(questions[x].question());
|
||||
console.log("x="+x+"; y="+x+"+"+questions[x].corresponds_to+"="+y);
|
||||
console.log("my answer: "+my.answers[x]+"; their answer: "+their.answers[y]);
|
||||
if (my.answers[x] * their.answers[y] > 1) {
|
||||
console.log("my answer: "+my.answers[x].answer+"; their answer: "+their.answers[y].answer);
|
||||
if (my.answers[x].answer * their.answers[y].answer > 1) {
|
||||
questions[x].color = "limegreen";
|
||||
questions[x].consent_level = 1;
|
||||
questions[x].unlocks_tab.unlocked = true;
|
||||
if (their.answers[y] == 3) questions[x].star = true;
|
||||
if (their.answers[y].answer == 3) questions[x].star = true;
|
||||
} else {
|
||||
questions[x].color = "lightcoral";
|
||||
questions[x].consent_level = -1;
|
||||
|
|
@ -76,7 +76,7 @@ function updateHTML(){
|
|||
<li class="range-label">Ja!</li>
|
||||
<li class="range-label">Frag nicht, mach einfach</li>
|
||||
</ul>
|
||||
<input type="range" min="0" max="3" steps="1" value="${my.answers[x]}" class="slider" id="slider_${x}">
|
||||
<input type="range" min="0" max="3" steps="1" value="${my.answers[x].answer}" class="slider" id="slider_${x}">
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
|
@ -164,7 +164,8 @@ function onChange() {
|
|||
// Background tasks
|
||||
my.last_changed = Date.now();
|
||||
let x = + ( this.id.split("_")[1] );
|
||||
my.answers[x] = this.value;
|
||||
my.answers[x].answer = this.value;
|
||||
my.answers[x].last_changed = Date.now();
|
||||
maybeSend(false);
|
||||
|
||||
// UI adjustments
|
||||
|
|
|
|||
Loading…
Reference in a new issue