-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomTyping.js
More file actions
70 lines (60 loc) · 2.03 KB
/
CustomTyping.js
File metadata and controls
70 lines (60 loc) · 2.03 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
var customTextBox = new TextBox(320,150,350,40,30);
var customCheckButton = new Button(380,200,180,40,"Check",30,xOffset=50);
var customNewQuestionButton = new Button(370,250,220,40,"New Question",30,xOffset=15);
var customGenerateQuestion = true;
var customQuestion;//customQuestion[0]=Question,customQuestion[1]=Answer,customQuestion[2]=Explanation
var customExplanation="";
var customFeedback="";
var temp;
var customTest = [];
var repeat = true;
var explanationTemp = [];
function customTyping(){
fill(255,238,153,100);
noStroke();
rect(735,155,615,525,20,0,0,20);
stroke(0);
customTextBox.update();
customCheckButton.update();
customNewQuestionButton.update();
if(customGenerateQuestion){
customGenerateQuestion = false;
while (repeat == true){
repeat = false;
temp=customQuestions[Math.floor(random(customQuestions.length))];
customQuestion=temp.split(";");
//test if the question already appeared
for (var i = 0;i<customTest.length;i++){
if (temp == customTest[i]){repeat = true;}
}
}
customTest.push(temp); repeat = true;//console.log(customTest);
//put !! where you wanna add another line
explanationTemp = customQuestion[2].split("!!");
customQuestion[2]="";
for (var j = 0;j<explanationTemp.length;j++){
customQuestion[2] += explanationTemp[j] + "\n";
}
}
if(customNewQuestionButton.clicked){
customTextBox.data="";
customExplanation = "";
customFeedback = "";
customGenerateQuestion = true;
}
if(customCheckButton.clicked){
if(customTextBox.data.toLowerCase().trim()==customQuestion[1].toLowerCase().trim()){
customFeedback="Correct!";
}else{
customFeedback="Try again"
}
customExplanation="Answer: "+customQuestion[1];
if (customQuestion[2] != customQuestion[1]){
customExplanation = customQuestion[2] + "\n" + customExplanation;
}
}
text(customQuestion[0],320,120);
text("Feedback: " + customFeedback,320,330);
text("Work/Explanation:",760,200);
text(customExplanation,760,250);
}