-
Notifications
You must be signed in to change notification settings - Fork 480
/
CSD U3 - complex - nested conditional.level
115 lines (115 loc) · 4.87 KB
/
CSD U3 - complex - nested conditional.level
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
<Gamelab>
<config><![CDATA[{
"game_id": 50,
"created_at": "2016-06-17T18:07:07.000Z",
"level_num": "custom",
"user_id": 1,
"properties": {
"skin": "gamelab",
"code_functions": {
"draw": null,
"drawSprites": null,
"World.mouseX": null,
"World.mouseY": null,
"World.frameRate": null,
"keyDown": null,
"keyWentUp": null,
"keyWentDown": null,
"var sprite = createSprite": null,
"setAnimation": null,
"sprite.height": null,
"sprite.width": null,
"x": null,
"y": null,
"rotation": null,
"shapeColor": null,
"background": null,
"fill": null,
"noFill": null,
"stroke": null,
"strokeWeight": null,
"noStroke": null,
"color": null,
"arc": null,
"ellipse": null,
"line": null,
"point": null,
"rect": null,
"regularPolygon": null,
"shape": null,
"text": null,
"textAlign": null,
"textFont": null,
"textSize": null,
"ifBlock": null,
"ifElseBlock": null,
"addOperator": null,
"subtractOperator": null,
"multiplyOperator": null,
"divideOperator": null,
"equalityOperator": null,
"inequalityOperator": null,
"greaterThanOperator": null,
"greaterThanOrEqualOperator": null,
"lessThanOperator": null,
"lessThanOrEqualOperator": null,
"andOperator": null,
"orOperator": null,
"notOperator": null,
"randomNumber_min_max": null,
"declareAssign_x": null,
"declareNoAssign_x": null,
"assign_x": null,
"comment_Sprites": null,
"comment_GameLab": null,
"comment_Variables": null,
"comment_Math": null,
"comment_Control": null,
"comment_Drawing": null,
"console.log": null
},
"show_d_pad": "true",
"edit_code": true,
"embed": "false",
"markdown_instructions": "# Possible Solution #1 - Nested Conditionals\r\n\r\nThe way you phrase the previous challenge says a lot about how you might approach solving it. For example, you might have phrased moving up and staying on screen as:\r\n\r\n\tIf the up arrow was pressed then check if the sprite hasn't gone off the top of the screen and move up.\r\n\r\nThis structure of first asking one question, and then asking a second question if the first was true is accomplished using a **nested if statement**. Nested if statements put one if statement inside another if statement. You can think of this as asking a question and then based on the answer asking another question before making a decision. We could pseudocode the previous phrase as:\r\n\r\n\tIf the up arrow was pressed\t// First Question\r\n \tIf my y > 0\t\t\t\t// Second Question\r\n \tmove up\t\t\t\t// Only runs if both questions were true\r\n\r\n\r\n# Do This\r\n\r\nHere's the same code from the challenge, with the up arrow using a nested conditional. \r\n\r\n* Use the same nested conditional pattern on the other 3 arrow keys.\r\n",
"start_blocks": "// Create a sprite\r\nvar sprite = createSprite(200, 100, 50, 50);\r\nsprite.shapeColor = \"red\";\r\n\r\nfunction draw() {\r\n background(\"white\");\r\n \r\n // Move the sprite in the direction of the arrow keys\r\n // But make sure it doesn't go off the screen\r\n if (keyDown(\"up\")) {\r\n if (sprite.y > 0) {\r\n sprite.y = sprite.y - 1;\r\n }\r\n }\r\n if (keyDown(\"down\")) {\r\n sprite.y = sprite.y + 1;\r\n }\r\n if (keyDown(\"left\")) {\r\n sprite.x = sprite.x - 1;\r\n }\r\n if (keyDown(\"right\")) {\r\n sprite.x = sprite.x + 1;\r\n }\r\n \r\n drawSprites();\r\n}",
"is_k1": "false",
"skip_instructions_popup": "false",
"never_autoplay_video": "false",
"disable_param_editing": "true",
"disable_variable_editing": "false",
"use_modal_function_editor": "false",
"use_contract_editor": "false",
"contract_highlight": "false",
"contract_collapse": "false",
"examples_highlight": "false",
"examples_collapse": "false",
"examples_required": "false",
"definition_highlight": "false",
"definition_collapse": "false",
"disable_examples": "false",
"droplet_tooltips_disabled": "false",
"lock_zero_param_functions": "false",
"free_play": "true",
"text_mode_at_start": "false",
"submittable": "false",
"hide_view_data_button": "true",
"debugger_disabled": "true",
"callout_json": "[]",
"hide_animation_mode": "false",
"instructions_important": "false",
"start_in_animation_tab": "false",
"all_animations_single_frame": "true",
"show_debug_watch": "true",
"pause_animations_by_default": "false",
"encrypted_examples": "p2HyMPVBrhwJX55iUS2lvbAboBSrPHgtqmBlu7DphCnNK9v9YXXHD5OyQs5h\nNcpy\n",
"hide_share_and_remix": "false",
"contained_level_names": null
},
"published": true,
"notes": "",
"level_concept_difficulty": {
}
}]]></config>
<blocks/>
</Gamelab>