-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch.js
More file actions
206 lines (148 loc) · 4.33 KB
/
sketch.js
File metadata and controls
206 lines (148 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
var jibu;
var hakiki;
var par;
var para;
var check;
var count = 0;
var storagee;
function setup() {
// createCanvas(windowWidth, windowHeight);
par = createP('Question');
jibu = createInput("Answer");
par.hide();
jibu.hide();
para = createP('');
//count = 0;
check = createP('');
questionAsked = select("#question");
answerGiven = select("#answer");
submitEntry = select("#submitEntry");
createQuiz = select("#createQuiz");
//createQuiz.hide();
takeQuiz = select("#takeQuiz");
refreshPage = select("#refreshPage");
//createQuiz.hide();
//takeQuiz.hide();
//refreshPage.hide();
//storagee = createButton('STORAGEE...');
// storagee.mousePressed(updateStorageList);
//takeQuiz = createButton('NEXT...');
// takeQuiz.hide();
takeQuiz.mousePressed(fanyaMambo);
refreshPage.mousePressed(pageReload)
loadQuestion();
newQuiz();
}
function draw() {
//background(205,200,205);
}
function newQuestion() {
if (questionAsked.value() != "" && answerGiven.value() != "") {
var key = questionAsked.value();
var value = answerGiven.value();
localStorage.setItem(key, value);
questionAsked.value('');
answerGiven.value('');
} else if (questionAsked.value() == "" || answerGiven.value() == "") {
alert ("Waoh! Don't leave any field empty!");
}
//refreshPage.show();
}
function loadQuestion() {
submitEntry.mousePressed(newQuestion);
}
function newQuiz() {
createQuiz.mousePressed(futaStorage);
}
function futaStorage() {
//alert("Warning This Will Delete Your Previous Quiz!");
if (confirm("If you press an OK button, your previous Quiz will be permanently deleted!")) {
txt = "You pressed OK!";
localStorage.clear();
location.reload();
} else {
txt = "You pressed Cancel!";
}
// localStorage.clear();
}
function fanyaMambo() {
par.show();
jibu.show();
var going = true;
// var count = 0;
//para = createP('');
para.html('');
jibu.value('');
jibu.class('jibu-input');
check.html('');
if (going && count < localStorage.length) {
//var kurasa = createP(localStorage.key(count));
// var kurasa2 = createP(localStorage.getItem(key(count));
par.html(localStorage.key(count));
par.class('question-paragraph');
//par.parent('wrapper');
// jibu = createInput("Jibu swali");
// hakiki = createButton('SUBMITANSWER');
// count++;
} else {
//pageReload();
// createP("QUIZ OVER");
alert ("Quiz Over! No more questions. Press RELOAD PAGE to take the quiz again or Press CREATE NEW QUIZ to make a new quiz");
par.hide();
jibu.hide();
takeQuiz.hide();
//button3.hide();
//button4.hide();
}
count++;
// for (var i= 0; i< localStorage.length; i++) {
// var kurasa = createP(localStorage.key(i));
// // var kurasa2 = createP(localStorage.getItem(key(count));
// jibu = createInput("Jibu swali");
// hakiki = createButton('SUBMITANSWER');
// }
jibu.changed (doSomething);
//jibu.input (doSomething);
}
function doSomething() {
para.html(jibu.value());
para.class('jibu-paragraph');
if (para.html().toUpperCase() == localStorage.getItem(localStorage.key(count-1)).toUpperCase()) {
console.log ("SUCCESS");
//var check = createP("Correct!");
check.html("Correct!");
check.class('correct');
//console.log (localStorage.getItem(localStorage.key(1)));
} else {
//var check = createP("Wrong!");
check.html("Wrong! " + "Answer is " + localStorage.getItem(localStorage.key(count-1)));
// check.html("Wrong!");
check.class('wrong');
console.log("WRONG");
console.log("Answer is " + localStorage.getItem(localStorage.key(count-1)));
//console.log (localStorage.getItem(localStorage.key(1)));
}
jibu.value('');
}
function updateStorageList() {
par = createP('N');
for (var i = 0; i < localStorage.length; i++) {
createP(localStorage.key(i));
//createP('....');
createP(localStorage.getItem(localStorage.key(i)));
}
// if (localStorage.getItem(localStorage.key(i)) == localStorage.getItem(localStorage.value(i))) {
//
// }
if (par.html() == localStorage.getItem(localStorage.key(0))) {
console.log ("SUCCESS");
console.log (localStorage.getItem(localStorage.key(1)));
} else {
console.log("WRONG");
console.log (localStorage.getItem(localStorage.key(1)));
}
//console.log(localStorage.getItem(localStorage.key(i)));
}
function pageReload() {
location.reload();
}