CPT PRG Code
CPT PRG Code
io/codePrint/
1 var score = 0;
2
3 // array list containing questions and their corresponding answer
4 var mathQuestions = [
5 ({
6 "question": "6 x 6",
7 "correct": "36",
8 }),
9 ({
10 "question": "120 - 120",
11 "correct": "0",
12 }),
13 ({
14 "question": "100 + 68",
15 "correct": "168",
16 }),
17 ({
18 "question": "12 - 11",
19 "correct": "1",
20 }),
21 ({
22 "question": "4 + 4",
23 "correct": "8",
24 }),
25 ({
26 "question": "200 / 2",
27 "correct": "100",
28 }),
29 ];
30
31 //function for accessing the questions and their answers
32 function displayQA(){
33 setText("label1", mathQuestions[0].question);
34 setText("label2", mathQuestions[1].question);
35 setText("label3", mathQuestions[2].question);
36 setText("label4", mathQuestions[3].question);
37 setText("label5", mathQuestions[4].question);
38 setText("label6", mathQuestions[5].question);
39 }
40
41 displayQA();
42
43 //when right answer is chosen, green color shows with a sound effect and
44 //score updates
45 onEvent("text_input1", "change", function( ) {
46 var input = getProperty("text_input1", "text");
47 if(input == mathQuestions[0].correct){
48 setProperty("text_input1", "background-color", "green");
49 setProperty("text_input15", "hidden", true);
50 playSound("sound://category_achievements/lighthearted_bonus_objective_2.mp3", false);
51 score++;
52
https://bakerfranke.github.io/codePrint/ 1/4
4/17/23, 10:24 PM https://bakerfranke.github.io/codePrint/
https://bakerfranke.github.io/codePrint/ 4/4