-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmissions_fi_obs.js
418 lines (402 loc) · 9.02 KB
/
missions_fi_obs.js
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
var missions = [
{
slug: 'intro',
desc: "The light gray cells in the array form an emoticon. Light up those cells with the cell(x,y) function.",
hints: ['Try drawing the other eye with "cell(4,1)"! function call.', 'The first number (argument) inside round brackets defines the X and the second defines the Y position of the cell being drawn (amd they are seperated with a comma ",")'],
func: function() {
cell(2,1);
cell(4,1);
cell(2,3);
cell(3,3);
cell(4,3);
},
example: function() {
cell(2,1); // We light up the left eye.
}
},
{
slug: 'while_intro',
desc: "Well that was a lot of work! Drawing multiple adjacent cells is easier with a while loop. Try changing the numbers in the code to understand it better, after that feel free to move to the next mission.",
func: function() {
cell(2,1);
cell(4,1);
var x = 2;
while(x <= 4) {
cell(x, 3);
x += 1;
}
},
example: function() {
// We draw the eyes
cell(2,1);
cell(4,1);
// We start drawing the mouth from X coordinate 2
var x = 2;
while(x <= 4) { // while x is less or equal to 4 -->
cell(x, 3); //...we light up a cell in the position of x
x += 1; //...and move one cell to the right (add one to the x)
}
}
},
{
slug: 'mouth_wider',
size: 7,
desc: "The mouth of the emoticon grew larger. Change the start and end coordinates of the mouth (while-loop) so that the mouth is in the right size.",
hints: [
'The mouth starts from the x coordinate 1 so we must set "var x = 1;"',
'The mouth ends in the x coordinate 5 so we must draw cells while the x is less or equal to 5 "while (x <= 5)"',
],
func: function() {
cell(2,1);
cell(4,1);
var x = 1;
while(x <= 5) {
cell(x, 3);
x += 1;
}
},
example: "prev_example"
},
{
slug: 'mouth_lower',
size: 7,
desc: "Change the height of the mouth!",
hints: [
'Try changing the second argument (y, the number 3) inside the round brackets.'
],
func: function() {
cell(2,1);
cell(4,1);
cell(3,3);
var x = 1;
while(x <= 5) {
cell(x, 5);
x += 1;
}
},
example: function() {
cell(2,1);
cell(4,1);
var x = 1;
while(x <= 5) {
cell(x, 3); //cell(x,y)
x += 1;
}
}
},
{
slug: 'for_intro',
size: 7,
desc: 'In this mission the while loop is replaced with a for-loop, which is just a shorthand for the while loop we had earlier. Both define a variable (var x = 1;) and plus a number (x += 1;) while a condition (x <= 5) is true. Try changing the code to understand everything better.',
func: 'func_prev',
example: function() {
cell(2,1);
cell(4,1);
cell(3,3);
// A new shorthand for writing the earlier loop:
for(var x = 1; x <= 5; x+=1) {
cell(x, 5);
}
/*
The old, technically identical loop:
var x = 1;
while(x <= 5) {
cell(x, 5); //cell(x,y)
x += 1;
}
*/
}
},
{
slug: 'nose_thing',
size: 7,
desc: "The nose of the emoticon grew larger and took space from the mouth. Make the mouth narrower and move it down!",
func: function() {
cell(2,1);
cell(4,1);
cell(3,3);
cell(3,4);
for(var x = 2; x <= 4; x+=1) {
cell(x,6);
}
},
example: function() {
cell(2,1);
cell(4,1);
cell(3,3);
cell(3,4);
// Change the coordinates of the mouth!
for(var x = 1; x <= 5; x+=1) {
cell(x,5); //cell(x,y);
}
}
},
{
slug: 'equals',
size: 7,
desc: "Let's try to draw an equals sign. Youl'll need two cell(x,y)-functions, but could it be possible to solve this with just one for-loop?",
func: function() {
for(var x = 1; x <= 5; x+=1) {
cell(x,2);
cell(x,4);
}
},
example: function() {
for(var x = 2; x <= 4; x+=1) {
cell(x,4);
}
}
},
{
slug: 'plus',
size: 7,
desc: "Let'd draw a plus sign. Move the horizontal line to the right position. After that you can try to draw a vertical line. If you are really smart you could maybe solve this with only one for-loop but try with two first!",
func: function() {
for(var x = 2; x <= 4; x+=1) {
cell(x,3);
cell(3,x);
}
},
example: function() {
for(var x = 1; x <= 5; x+=1) {
cell(x,5);
}
}
},
{
slug: 'box',
size: 7,
desc: "Let's draw a box. Try to solve this with two for-loops at maximum. It's also possible with only one (; <br>Notice that the cell(x,y)-functions are turned into comments, so that you could see the example better. Remove the slashes ( // ) , so that they turn back into regular code.",
func: function() {
for(var x = 1; x <= 5; x++) {
cell(x, 1)
cell(x, 5);
cell(1, x);
cell(5, x);
}
},
example: function() {
for(var k = 2; k <= 4; k+=1) {
//cell(k,3);
//cell(3,k);
}
}
},
{
slug: 'line',
size: 7,
desc: "Hmmmm",
hints: ['So the x and y should get larger simultaneously O___o', 'So x should always equal to y?', 'But if x gets the value of k then what should y get?'],
func: function() {
for(var k = 0; k <= 6; k+=1) {
cell(k,k);
}
},
example: function() {
for(var k = 2; k <= 4; k+=1) {
//cell(k,0);
}
}
},
{
slug: 'char-x',
size: 7,
desc: 'You can use + and - signs in argument. for example: cell(x+3, 4), cell(x, 4-y), cell(k+3, k). What would be the correct calculation in this situtation? <br> Be cautious about accidentally drawing outside the array!',
func: function() {
for(var k = 0; k <= 6; k+=1) {
cell(k,k);
cell(k, 6-k);
}
},
example: function() {
for(var k = 0; k <= 6; k+=1) {
cell(k,k);
}
}
},
{
slug: 'happy',
size: 7,
desc: "You can use + and - signs in argument. for example: cell(x+3, 4), cell(x, 4-y), cell(k+3, k). You'll need 4 cell(x,y)-functions.",
func: function() {
cell(2,1);
cell(4,1);
for(var k = 0; k <= 2; k+=1) {
cell(3+k,5-k);
cell(3-k,5-k);
}
},
example: function() {
//cell(4,1);
for(var k = 0; k <= 1; k+=1) {
//cell(3+k,5-k);
}
}
},
{
slug: 'solid_box',
size: 7,
desc: "Loopception?",
func: function() {
for(var x = 1; x <= 5; x+=1) {
for(var y = 1; y <= 5; y+=1) {
cell(x,y);
}
}
},
example: function() {
for(var x = 1; x <= 5; x+=1) {
//cell(x,1);
}
},
hints: [
"Currently a cell is being drawn to every x coordinate. What if instead of a cell a vertical line would be drawn to every x-coordinate?",
"A for loop inside a for loop? O___o"
]
},
{
slug: 'marble_flooring',
size: 7,
desc: "Now we should just make our area larger.",
func: function() {
for(var x = 0; x <= 6; x+=1) {
for(var y = 0; y <= 6; y+=1) {
cell(x,y);
}
}
},
example: function() {
for(var x = 1; x <= 5; x+=1) {
for(var y = 1; y <= 5; y+=1) {
//cell(x,y);
}
}
}
},
{
slug: 'block_of_flats',
size: 7,
desc: "A block of flats",
hints: [
'So we should draw a line to every other y coordinate?'
],
func: function() {
for(var x = 0; x <= 6; x+=1) {
for(var y = 0; y <= 6; y+=2) {
cell(x,y);
}
}
},
example: function() {
for(var x = 0; x <= 6; x+=1) {
for(var y = 0; y <= 6; y+=1) {
//cell(x,y);
}
}
}
},
{
slug: 'pillars',
size: 7,
desc: "Pillars",
func: function() {
for(var x = 0; x <= 6; x+=2) {
for(var y = 0; y <= 6; y+=2) {
cell(x,y);
}
}
},
example: function() {
for(var x = 0; x <= 6; x+=1) {
for(var y = 0; y <= 6; y+=2) {
//cell(x,y);
}
}
}
},
{
slug: 'wire_basket',
size: 7,
desc: "Wire basket. Use two for-loop at maximum, possible with only one.",
hints: [
'Now is time to combine everything you have learned in previous challenges'
],
func: function() {
for(var a = 0; a <= 6; a+=2) {
for(var b = 0; b <= 6; b+=1) {
cell(a,b);
cell(b,a);
}
}
},
example: function() {
for(var a = 0; a <= 6; a+=1) {
for(var b = 0; b <= 6; b+=2) {
//cell(a,b);
}
}
}
},
{
slug: 'stairs',
size: 7,
desc: "Stairs. You need two for loops one 1-2 cell(x,y) functions.",
hints: [
'Remember the challenge about drawing a straight line? There is something similar about this.',
'So the maximum value of x always equals to height of the current horizontal line?'
],
func: function() {
for(var y = 0; y <= 6; y+=1) {
for(var x = 0; x <= y; x+=1) {
cell(x,y);
}
}
},
example: function() {
for(var y = 0; y <= 6; y+=1) {
for(var x = 0; x <= 6; x+=1) {
//cell(x,y);
}
}
}
},
{
slug: 'pyramid',
size: 7,
desc: "Pyramid",
func: function() {
for(var y = 0; y <= 3; y+=1) {
for(var x = -y; x <= y; x+=1) {
cell(3+x,y);
}
}
},
example: function() {
for(var y = 0; y <= 6; y+=1) {
for(var x = 0; x <= y; x+=1) {
//cell(x,y);
}
}
}
},
{
slug: 'tiles',
size: 7,
desc: "Vinoneliö",
func: function() {
for(var y = 0; y <= 3; y+=1) {
for(var x = -y; x <= y; x+=1) {
cell(3+x,y);
cell(3+x,6-y);
}
}
},
example: function() {
for(var y = 0; y <= 3; y+=1) {
for(var x = -y; x <= y; x+=1) {
//cell(3+x,y);
}
}
},
}
]