From 59f13f38fec7c292a2e287e6d9258ed816e9e956 Mon Sep 17 00:00:00 2001 From: Vera Reynolds Date: Sat, 14 Oct 2017 13:23:02 -0600 Subject: [PATCH] fix up JS snake game instructions --- lib/site_extensions/javascript-snake-game.rb | 2 +- sites/en/javascript-snake-game/lesson-2.step | 19 ++++++++++++++++++- sites/en/javascript-snake-game/lesson-6.step | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/site_extensions/javascript-snake-game.rb b/lib/site_extensions/javascript-snake-game.rb index 07a6d81fa..27a7ad834 100644 --- a/lib/site_extensions/javascript-snake-game.rb +++ b/lib/site_extensions/javascript-snake-game.rb @@ -9,7 +9,7 @@ def js_expected_results(lesson) source_code :js, File.read(src_path) - h4 'How the game should work:' + h4 'How the game should work so far:' canvas id: 'chunk-game', height: '600', width: '800' diff --git a/sites/en/javascript-snake-game/lesson-2.step b/sites/en/javascript-snake-game/lesson-2.step index 03a0824cc..ef1924d9f 100644 --- a/sites/en/javascript-snake-game/lesson-2.step +++ b/sites/en/javascript-snake-game/lesson-2.step @@ -86,9 +86,26 @@ js_expected_results 'lesson-2' MARKDOWN end + step "Comments" do + markdown <<-MARKDOWN + 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. + Here's what comments look like in JavaScript: + + ```js + // this is a one line comment, here we're creating an array + var drawableObjects = [drawableSnake]; + /* + this is a multi line comment + here we're drawing the snake + */ + CHUNK.draw(drawableObjects); + ``` + MARKDOWN + end + step "Play Time!" do markdown <<-MARKDOWN - * Add comments underneath each line explaining what it does in plain old english. + * Add comments above each line explaining what it does in plain old english. * Change the color of the snake. * Make the snake longer than just 1 segment! * Draw something in addition to the snake. Perhaps an apple or a wall? Make diff --git a/sites/en/javascript-snake-game/lesson-6.step b/sites/en/javascript-snake-game/lesson-6.step index 1f45bf777..41e5c5163 100644 --- a/sites/en/javascript-snake-game/lesson-6.step +++ b/sites/en/javascript-snake-game/lesson-6.step @@ -58,6 +58,25 @@ MARKDOWN js_expected_results 'lesson-6' markdown <<-MARKDOWN + ### Switch statement + + A `switch` statement is another way to organize a seried of `if` and `else if`s. Here's an example: + + ```js + switch(color) { + case "red": + return { action: "stop" }; + case "orange": + return { action: "wait" }; + case "green": + return { action: "go" }; + default: + return { action: "unknown" }; + } + ``` + + 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) + ### Play Time! * Use a switch statement instead of a series of ifs