@@ -24,7 +24,7 @@ function new_article_query(_data) {
24
24
} else {
25
25
article_name . innerHTML = search . value ;
26
26
data = _data ;
27
- console . log ( data ) ;
27
+ // console.log(data);
28
28
load_question ( ) ;
29
29
}
30
30
}
@@ -50,8 +50,13 @@ function load_question() {
50
50
q_idx = 0 ;
51
51
make_request ( curQuery , new_article_query ) ;
52
52
} else {
53
- question_body . innerHTML = data [ 'questions' ] [ q_idx ] [ 1 ] ;
54
53
label = data [ 'questions' ] [ q_idx ] [ 0 ] ;
54
+
55
+ question_body . innerHTML = convert_to_redacted (
56
+ data [ 'questions' ] [ q_idx ] [ 1 ] ,
57
+ data [ 'questions' ] [ q_idx ] [ 2 ] ,
58
+ label ) ;
59
+
55
60
answers = [ ] ;
56
61
correct_answer = data [ 'questions' ] [ q_idx ] [ 2 ] ;
57
62
answers . push ( correct_answer ) ;
@@ -81,33 +86,36 @@ function randomFromArr(arr) {
81
86
return arr [ Math . floor ( Math . random ( ) * arr . length ) ] ;
82
87
}
83
88
84
- function answered_a ( ) {
85
- console . log ( correct_answer ) ;
86
- console . log ( answer_a . innerHTML ) ;
87
- if ( correct_answer === answer_a . innerHTML ) {
88
- answer_response_label . innerHTML = "Correct!" ;
89
- } else {
90
- answer_response_label . innerHTML = "That's wrong..." ;
89
+ function convert_to_redacted ( text , answer , label ) {
90
+ _answer = answer ;
91
+ if ( label === "NUMBER" ) {
92
+ _answer = answer . replace ( / [ ^ 0 - 9 ] / g , '' ) ;
93
+ if ( _answer === "" ) {
94
+ _answer = answer ;
95
+ }
91
96
}
92
- answer_response_label . style . display = "block" ;
97
+ return text . replace ( _answer , "❓" ) ;
93
98
}
94
99
95
- function answered_b ( ) {
96
- if ( correct_answer === answer_b . innerHTML ) {
100
+ function handleAnswerResponse ( answer_given ) {
101
+ if ( correct_answer === answer_given ) {
97
102
answer_response_label . innerHTML = "Correct!" ;
98
103
} else {
99
104
answer_response_label . innerHTML = "That's wrong..." ;
100
105
}
101
106
answer_response_label . style . display = "block" ;
102
107
}
103
108
109
+ function answered_a ( ) {
110
+ handleAnswerResponse ( answer_a . innerHTML ) ;
111
+ }
112
+
113
+ function answered_b ( ) {
114
+ handleAnswerResponse ( answer_b . innerHTML ) ;
115
+ }
116
+
104
117
function answered_c ( ) {
105
- if ( correct_answer === answer_c . innerHTML ) {
106
- answer_response_label . innerHTML = "Correct!" ;
107
- } else {
108
- answer_response_label . innerHTML = "That's wrong..." ;
109
- }
110
- answer_response_label . style . display = "block" ;
118
+ handleAnswerResponse ( answer_c . innerHTML ) ;
111
119
}
112
120
113
121
/**
0 commit comments