0% found this document useful (0 votes)
71 views4 pages

Bakerfranke Github Io

This document contains the code for a quiz game that tests the player's knowledge of soccer players. It sets up variables to track the questions, correct answers, score, and current question number. It also defines functions for displaying the next question, checking the selected answer, and updating the score. The questions are multiple choice lists of player names from a dataset. It will loop through 16 questions, showing the player information for the correct answer after each turn before moving to the next question.

Uploaded by

Joseph Bayne
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views4 pages

Bakerfranke Github Io

This document contains the code for a quiz game that tests the player's knowledge of soccer players. It sets up variables to track the questions, correct answers, score, and current question number. It also defines functions for displaying the next question, checking the selected answer, and updating the score. The questions are multiple choice lists of player names from a dataset. It will loop through 16 questions, showing the player information for the correct answer after each turn before moving to the next question.

Uploaded by

Joseph Bayne
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

2/9/23, 9:44 AM https://bakerfranke.github.

io/codePrint/

Guess The Player


3
4 // Set questions and answers to my questions
5 var question1 = [3,5,8,1,2];
6 var correct1 = 1;
7 var question2 = [4,8,12,9,15];
8 var correct2 = 2;
9 var question3 = [3,2,10,9,1];
10 var correct3 = 3;
11 var question4 = [12,7,9,6,1];
12 var correct4 = 4;
13 var question5 = [13,2,5,3,11];
14 var correct5 = 0;
15 var question6 = [11,7,9,6,0];
16 var correct6 = 3;
17 var question7 = [12,2,9,6,10];
18 var correct7 = 4;
19 var question8 = [12,2,0,6,15];
20 var correct8 = 4;
21 var question9 = [15,5,9,11,1];
22 var correct9 = 3;
23 var question10 = [11,2,14,6,15];
24 var correct10 = 2;
25 var question11 = [7,3,2,6,10];
26 var correct11 = 2;
27 var question12 = [8,4,9,3,2];
28 var correct12 = 0;
29 var question13 = [9,2,8,6,7];
30 var correct13 = 4;
31 var question14 = [6,2,9,0,10];
32 var correct14 = 3;
33 var question15 = [4,0,15,6,14];
34 var correct15 = 0;
35 var question16 = [15,14,4,0,11];
36 var correct16 = 0;
37 // set a correct answer variable
38 var correct;
39 // set a variable to keep track of the score
40 var score = 0;
41 // set a variable to keep track of the question your on
42 var nextCounter = 0;
43 // sets a variable for the players flag
44 var playerCountry;
45 // sets a variable for the ploayers club
46 var playerClub;
47 // sets a variable for the players position
48 var playerPos;
49 // sets a variable for the players name
50 var playerName;
51 // sets the data for the player list
52 var dataSet = [
53 ["Kylian Mbappé","bit.ly/3XJ048W","bit.ly/3XOaILW","ST"],
54 ["Kevin De Bruyne","bit.ly/3XOYOkY","bit.ly/3R8NXjc","CM"],

https://bakerfranke.github.io/codePrint/ 1/4
2/9/23, 9:44 AM https://bakerfranke.github.io/codePrint/

55 ["Robert Lewandowski","bit.ly/3wSSf53","bit.ly/3WMhyQu", "ST"],


56 ["Karim Benzema","bit.ly/3kQ54Kk","bit.ly/3j2QiQc","ST"],
57 ["Lionel Messi","bit.ly/3HCPFpY","bit.ly/3XJ1bpk","CAM"],
58 ["Mohamed Salah","bit.ly/3kDSFZU","bit.ly/3HK3ump","RW"],
59 ["Manuel Neuer","bit.ly/3HcFJlt","bit.ly/3XJMWjU","GK"],
60 ["Erling Haaland","bit.ly/3XOYOkY","bit.ly/3kLxQMf","ST"],
61 ["Sadio Mane","bit.ly/3DHtIDR","bit.ly/3Y9yS2X","LW"],
62 ["Virgil van Dijk","bit.ly/3kDSFZU","bit.ly/3wGCXzV","CB"],
63 ["Neymar Jr","bit.ly/3HCPFpY","bit.ly/3Y5jgh9","LW"],
64 ["A. Robertson","bit.ly/3DHtIDR","bit.ly/3R9SUbi","LB"],
65 ["Mike Maignan","bit.ly/3H9r1f7","bit.ly/3j2QiQc","GK"],
66 ["Leon Goretzka","bit.ly/3HcFJlt","bit.ly/3XJMWjU","CM"],
67 ["Vinicius Jr.","bit.ly/3kQ54Kk","bit.ly/3Y5jgh9","LW"],
68 ["Trent Alexander-Arnold","bit.ly/3kDSFZU","bit.ly/3RaV4HH","RB"],
69 ];
70
71 // start
72 nextPlayer(question1, correct1);
73
74 //Allows you to restart the App after getting to the end
75 onEvent("restartButton", "click", function( ) {
76 setScreen("homeScreen");
77 nextCounter = 0;
78 score = 0;
79 // start
80 nextPlayer(question1, correct1);
81 });
82 //Allows you to chose Answer 1 and send whbat nextCounter is
83 onEvent("button0", "click", function( ) {
84 showRightWrong(0,nextCounter);
85 });
86 //Allows you to chose Answer 2
87 onEvent("button1", "click", function( ) {
88 showRightWrong(1,nextCounter);
89 });
90 //Allows you to chose Answer 3
91 onEvent("button2", "click", function( ) {
92 showRightWrong(2,nextCounter);
93 });
94 //Allows you to chose Answer 4
95 onEvent("button3", "click", function( ) {
96 showRightWrong(3,nextCounter);
97 });
98 //Allows you to chose Answer 5
99 onEvent("button4", "click", function( ) {
100 showRightWrong(4,nextCounter);
101 });
102
103
104 //This function allows for the information to appear on screen 1
105 // nextPlayer function parameters are q=current question list and c=correct answer index for question
106 function nextPlayer(q,c) {
107 // THIS IS THE SEQUENCE FOR EACH QUESTION SCREEN
108 // set correct to correct answer index for question
109 correct = c;
110 // increment nextCounter

https://bakerfranke.github.io/codePrint/ 2/4
2/9/23, 9:44 AM https://bakerfranke.github.io/codePrint/

111 nextCounter = nextCounter + 1;


112 // clear right/wrong image
113 setProperty("rightWrong", "image","");
114 // ITERATION-put labels on buttons by looping through current question list
115 for (var i = 0; i <= 4; i++) {
116 playerName = dataSet[q[i]][0];
117 setText("button"+i, playerName);
118 }
119 console.log("Correct name is: " + dataSet[q[c]][0]);
120 // set country, club and position for question based on correct answer
121 playerCountry = dataSet[q[c]][2];
122 playerClub = dataSet[q[c]][1];
123 playerPos = dataSet[q[c]][3];
124
125 // sets images for club and country
126 setProperty("image1", "image","http://"+playerClub);
127 setProperty("image2", "image","http://"+playerCountry);
128 // sets text for position
129 setText("label1",playerPos);
130
131 // Resets nextCounter back to 0 if pasted question 16
132 // Sets screen to scoreScreen and tells you your score out of 16
133 if(nextCounter == 16) {
134 nextCounter = 0;
135 setScreen("scoreScreen");
136 setText("scoreText", "You got " + score + " out of 16!");
137 }
138 }
139 //increases score by 1 for each question you get right
140 //parameters are x=answer based on button clicked and y=nextCounter value
141 function showRightWrong(x,y) {
142 // THIS IS SEQUENCE TO LET PLAYER KNOW IF ANSWER WAS RIGHT OR WRONG AND TO GO TO NEXT QUESTION AND CAL
143 // correct is set in nextPlayer function
144 if(x == correct){
145 score = score + 1;
146 setProperty("rightWrong", "image","https://cdn.pixabay.com/photo/2016/03/31/14/37/check-mark-129278
147 }
148 else {
149 setProperty("rightWrong", "image", "https://upload.wikimedia.org/wikipedia/commons/thumb/5/5f/Red_X
150 }
151 // move to next with a delay of half a second
152 setTimeout(function() {
153 if(y == 1){
154 nextPlayer(question2,correct2);
155 }
156 if(y == 2){
157 nextPlayer(question3,correct3);
158 }
159 if(y == 3){
160 nextPlayer(question4,correct4);
161 }
162 if(y == 4){
163 nextPlayer(question5,correct5);
164 }
165 if(y == 5){
166 nextPlayer(question6,correct6);

https://bakerfranke.github.io/codePrint/ 3/4
2/9/23, 9:44 AM https://bakerfranke.github.io/codePrint/

167 }
168 if(y == 6){
169 nextPlayer(question7,correct7);
170 }
171 if(y == 7){
172 nextPlayer(question8,correct8);
173 }
174 if(y == 8){
175 nextPlayer(question9,correct9);
176 }
177 if(y == 9){
178 nextPlayer(question10,correct10);
179 }
180 if(y == 10){
181 nextPlayer(question11,correct11);
182 }
183 if(y == 11){
184 nextPlayer(question12,correct12);
185 }
186 if(y == 12){
187 nextPlayer(question13,correct13);
188 }
189 if(y == 13){
190 nextPlayer(question14,correct14);
191 }
192 if(y == 14){
193 nextPlayer(question15,correct15);
194 }
195 if(y == 15){
196 nextPlayer(question16,correct16);
}
}, 500);
}

PDF document made with CodePrint using Prism

https://bakerfranke.github.io/codePrint/ 4/4

You might also like