Skip to content

Commit a74f8cf

Browse files
authored
Merge pull request #624 from vreynolds/fix-js-snake-docs
fix up JS snake game instructions
2 parents 622e420 + 59f13f3 commit a74f8cf

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

lib/site_extensions/javascript-snake-game.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def js_expected_results(lesson)
99

1010
source_code :js, File.read(src_path)
1111

12-
h4 'How the game should work:'
12+
h4 'How the game should work so far:'
1313

1414
canvas id: 'chunk-game', height: '600', width: '800'
1515

sites/en/javascript-snake-game/lesson-2.step

+18-1
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,26 @@ js_expected_results 'lesson-2'
8686
MARKDOWN
8787
end
8888

89+
step "Comments" do
90+
markdown <<-MARKDOWN
91+
Sometimes it's nice to leave a clarifying note to future readers of the code (this could very well be you!) in plain English. This is called a comment, and it is only intended for humans to read, the computer knows to ignore them.
92+
Here's what comments look like in JavaScript:
93+
94+
```js
95+
// this is a one line comment, here we're creating an array
96+
var drawableObjects = [drawableSnake];
97+
/*
98+
this is a multi line comment
99+
here we're drawing the snake
100+
*/
101+
CHUNK.draw(drawableObjects);
102+
```
103+
MARKDOWN
104+
end
105+
89106
step "Play Time!" do
90107
markdown <<-MARKDOWN
91-
* Add comments underneath each line explaining what it does in plain old english.
108+
* Add comments above each line explaining what it does in plain old english.
92109
* Change the color of the snake.
93110
* Make the snake longer than just 1 segment!
94111
* Draw something in addition to the snake. Perhaps an apple or a wall? Make

sites/en/javascript-snake-game/lesson-6.step

+19
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ MARKDOWN
5858
js_expected_results 'lesson-6'
5959

6060
markdown <<-MARKDOWN
61+
### Switch statement
62+
63+
A `switch` statement is another way to organize a seried of `if` and `else if`s. Here's an example:
64+
65+
```js
66+
switch(color) {
67+
case "red":
68+
return { action: "stop" };
69+
case "orange":
70+
return { action: "wait" };
71+
case "green":
72+
return { action: "go" };
73+
default:
74+
return { action: "unknown" };
75+
}
76+
```
77+
78+
Can you figure out how to replace our snake game code above with a `switch` statement? (Don't worry, you'll see how we do it in the next lesson)
79+
6180
### Play Time!
6281

6382
* Use a switch statement instead of a series of ifs

0 commit comments

Comments
 (0)