@@ -50,10 +50,11 @@ <h2 style="text-align:center;" id="question-number">Loading...</h2>
50
50
< script >
51
51
var max_econ , max_dipl , max_govt , max_scty ; // Max possible scores
52
52
max_econ = max_dipl = max_govt = max_scty = 0 ;
53
- var econ , dipl , govt , scty ; // User's scores
54
- econ = dipl = govt = scty = 0 ;
53
+ let econ_array = new Array ( questions . length ) ;
54
+ let dipl_array = new Array ( questions . length ) ;
55
+ let govt_array = new Array ( questions . length ) ;
56
+ let scty_array = new Array ( questions . length ) ;
55
57
var qn = 0 ; // Question number
56
- var prev_answer = null ;
57
58
init_question ( ) ;
58
59
for ( var i = 0 ; i < questions . length ; i ++ ) {
59
60
max_econ += Math . abs ( questions [ i ] . effect . econ )
@@ -64,7 +65,7 @@ <h2 style="text-align:center;" id="question-number">Loading...</h2>
64
65
function init_question ( ) {
65
66
document . getElementById ( "question-text" ) . innerHTML = questions [ qn ] . question ;
66
67
document . getElementById ( "question-number" ) . innerHTML = "Question " + ( qn + 1 ) + " of " + ( questions . length ) ;
67
- if ( prev_answer == null ) {
68
+ if ( qn == 0 ) {
68
69
document . getElementById ( "back_button" ) . style . display = 'none' ;
69
70
document . getElementById ( "back_button_off" ) . style . display = 'block' ;
70
71
} else {
@@ -75,40 +76,40 @@ <h2 style="text-align:center;" id="question-number">Loading...</h2>
75
76
}
76
77
77
78
function next_question ( mult ) {
78
- econ + = mult * questions [ qn ] . effect . econ
79
- dipl + = mult * questions [ qn ] . effect . dipl
80
- govt + = mult * questions [ qn ] . effect . govt
81
- scty + = mult * questions [ qn ] . effect . scty
79
+ econ_array [ qn ] = mult * questions [ qn ] . effect . econ
80
+ dipl_array [ qn ] = mult * questions [ qn ] . effect . dipl
81
+ govt_array [ qn ] = mult * questions [ qn ] . effect . govt
82
+ scty_array [ qn ] = mult * questions [ qn ] . effect . scty
82
83
qn ++ ;
83
- prev_answer = mult ;
84
84
if ( qn < questions . length ) {
85
85
init_question ( ) ;
86
86
} else {
87
87
results ( ) ;
88
88
}
89
89
}
90
+
90
91
function prev_question ( ) {
91
- if ( prev_answer == null ) {
92
+ if ( qn == 0 ) {
92
93
return ;
93
94
}
94
95
qn -- ;
95
- econ -= prev_answer * questions [ qn ] . effect . econ ;
96
- dipl -= prev_answer * questions [ qn ] . effect . dipl ;
97
- govt -= prev_answer * questions [ qn ] . effect . govt ;
98
- scty -= prev_answer * questions [ qn ] . effect . scty ;
99
- prev_answer = null ;
100
96
init_question ( ) ;
101
-
102
97
}
98
+
103
99
function calc_score ( score , max ) {
104
100
return ( 100 * ( max + score ) / ( 2 * max ) ) . toFixed ( 1 )
105
101
}
102
+
106
103
function results ( ) {
104
+ let final_econ = econ_array . reduce ( ( a , b ) => a + b , 0 )
105
+ let final_dipl = dipl_array . reduce ( ( a , b ) => a + b , 0 )
106
+ let final_govt = govt_array . reduce ( ( a , b ) => a + b , 0 )
107
+ let final_scty = scty_array . reduce ( ( a , b ) => a + b , 0 )
107
108
location . href = `results.html`
108
- + `?e=${ calc_score ( econ , max_econ ) } `
109
- + `&d=${ calc_score ( dipl , max_dipl ) } `
110
- + `&g=${ calc_score ( govt , max_govt ) } `
111
- + `&s=${ calc_score ( scty , max_scty ) } `
109
+ + `?e=${ calc_score ( final_econ , max_econ ) } `
110
+ + `&d=${ calc_score ( final_dipl , max_dipl ) } `
111
+ + `&g=${ calc_score ( final_govt , max_govt ) } `
112
+ + `&s=${ calc_score ( final_scty , max_scty ) } `
112
113
}
113
114
</ script >
114
115
</ body >
0 commit comments