Skip to content

Commit 3cade48

Browse files
wnstncourtney
authored andcommitted
added introduction and additional steps for basic js curriculum
1 parent b530b71 commit 3cade48

File tree

6 files changed

+305
-120
lines changed

6 files changed

+305
-120
lines changed

sites/en/docs/docs.step

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@ site_desc 'frontend', <<-MARKDOWN
2828
HTML + CSS for beginners. Make a website, no server required!
2929
MARKDOWN
3030

31+
h1 'Javascript'
32+
3133
site_desc 'javascript-snake-game', <<-MARKDOWN
32-
A Javascript specific curriculum that walks you through building a simple game.
34+
A beginner Javascript specific curriculum that walks you through building a simple game.
3335
MARKDOWN
3436

3537
site_desc 'javascript-to-do-list', <<-MARKDOWN
36-
An all JavaScript curriculum that builds a simple to do list application using AJAX and jQuery.
38+
An intermediate all JavaScript curriculum that builds a simple to do list application using AJAX and jQuery.
3739
MARKDOWN
3840

3941
site_desc 'javascript-to-do-list-with-react', <<-MARKDOWN
40-
An all JavaScript curriculum that builds a simple to do list application using AJAX, jQuery, and React. Meant for
42+
An advanced all JavaScript curriculum that builds a simple to do list application using AJAX, jQuery, and React. Meant for
4143
students with some exposure to JavaScript.
4244
MARKDOWN
4345

36.9 KB
Loading
Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
# Lesson 1 - Building Snake in JavaScript
2-
31
markdown <<-MARKDOWN
4-
Today, we're going to recreate the classic game snake in the Javascript
5-
programming language.
2+
3+
### Goal
4+
5+
Today, we're going to recreate the classic game ~SNAKE!~ in the Javascript programming language.
6+
By the end of this session, you should understand the basics of the JavaScript language and how you can use it in a web browser.
7+
8+
The game you are going to create is going to work quite a bit like this:
9+
610
MARKDOWN
711

812
canvas id: 'chunk-game', height: 600, width: 800
@@ -12,45 +16,30 @@ script src: 'js/chunk.js'
1216
script src: 'js/snake.js'
1317

1418
markdown <<-MARKDOWN
15-
### Download the tutorial
16-
17-
Before you can start the tutorial, you'll need to <a
18-
href="js-snake-game-tutorial.zip">download the tutorial</a> to your computer
19-
to edit the source code.
20-
21-
### Launch your programming environment
22-
23-
When programming, you'll generally want these tools on hand:
24-
25-
* Your browser to see the code running (I recommend Chrome)
26-
* A text editor to change the code (I recommend <a
27-
href="http://www.sublimetext.com/">Sublime</a>)
28-
* A javascript console so you can experiment and print out debugging
29-
messages. This is built into your browser.
30-
31-
Once you have these tools available, we need to open the files we'll be working with:
32-
33-
* Open game/snake.js in your text editor
34-
* Open game/index.html in your browser
35-
* Open your browser's javascript console
36-
* type `alert("hello world");` in your browser's javascript console and
37-
dismiss the window that pops up
38-
39-
<img src='img/helloworld.png' height="300" width="600">
40-
41-
### Stop and reflect
42-
43-
* The javascript console is one of the fastest ways to get feedback on
44-
whether the code does what you expect. How else can you get feedback about whether
45-
your code does what you expect?
46-
* Why shouldn't you use Word or Google Docs to edit code?
47-
48-
### Helpful Links
49-
50-
* <a href="https://developers.google.com/chrome-developer-tools/">How to launch dev tools in chrome.</a>
51-
* <a href="http://www.microsoft.com/en-us/download/details.aspx?id=18359">How to launch dev tools in internet explorer.</a>
52-
* <a href="https://developer.mozilla.org/en-US/Firefox_OS/Debugging/Setting_up">How to launch dev tools in firefox.</a>
53-
* <a href="https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/UsingExtensionBuilder/UsingExtensionBuilder.html">How to launch dev tools in safari.</a>
19+
20+
### Meta-Goal
21+
22+
When you have completed today's goal of creating a browser based game you should understand:
23+
24+
* The basic syntax of JavaScript
25+
* How to create, view and debug JavaScript
26+
* How to use JavaScript with external libraries.
27+
* How to incrementally build out a JavaScript application.
28+
29+
### Schedule
30+
31+
* 2-ish hours of basic JavaScript syntax.
32+
* 3-ish hours of creating and playing with a Javascript game and animations.
33+
34+
This is just a rough guideline, not a mandate. Some steps you'll go
35+
over and some you'll go under. It'll all work out by the end of the
36+
day. Probably.
37+
38+
Before you can start the tutorial, you'll need to <a href="js-snake-game-tutorial.zip">download the tutorial</a>
39+
to your computer to edit the source code.
40+
41+
Once you've downloaded the zip archive file, you will need to extract the contents and open index.html with your browser. If you have trouble extracting the files or opening them, get an instructor to help you out.
42+
5443
MARKDOWN
5544

56-
next_step 'lesson-2'
45+
next_step 'lesson-1'
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
goals do
2+
goal "Setup your programming environment"
3+
goal "Be able to use the basic building blocks of JavaScript code"
4+
goal "Do simple calculations"
5+
goal "Use and understand variables"
6+
goal "Use and understand arrays"
7+
goal "Use loops and conditional statements"
8+
end
9+
10+
overview do
11+
message <<-MARKDOWN
12+
JavaScript is a fully featured programming language with variables, loops,
13+
and conditionals. Just like Ruby, Java, Python, and PHP, you can use JavaScript
14+
to do math, model large systems, and perform complex calculations – all in your browser!
15+
In this lesson, we'll learn about the fundamentals of the JavaScript programming language.
16+
MARKDOWN
17+
end
18+
19+
steps do
20+
step "Launch your programming environment" do
21+
message <<-MARKDOWN
22+
23+
When programming, you'll generally want these tools on hand:
24+
25+
* Your browser to see the code running (I recommend Chrome)
26+
* A text editor to change the code (I recommend <a
27+
href="http://www.sublimetext.com/">Sublime</a>)
28+
* A javascript console so you can experiment and print out debugging
29+
messages. This is built into your browser.
30+
31+
Some helpful links for browser consoles:
32+
33+
* <a href="https://developer.chrome.com/devtools">How to launch dev tools in chrome.</a>
34+
* <a href="https://msdn.microsoft.com/en-us/library/ie/bg182326.aspx">How to launch dev tools in internet explorer.</a>
35+
* <a href="https://developer.mozilla.org/en-US/docs/Tools/Browser_Console">How to launch dev tools in firefox.</a>
36+
* <a href="https://developer.apple.com/library/mac/documentation/AppleApplications/Conceptual/Safari_Developer_Guide/GettingStarted/GettingStarted.html">How to launch dev tools in safari.</a>
37+
38+
Once you have these tools available, we need to open the files we'll be working with:
39+
40+
* Open game/snake.js in your text editor
41+
* Open game/index.html in your browser
42+
43+
44+
Now open up your browser's developer tools, and click over to the console tab. Type the following code:
45+
MARKDOWN
46+
47+
source_code :javascript, <<-JAVASCRIPT
48+
console.log('programming!');
49+
JAVASCRIPT
50+
51+
message <<-MARKDOWN
52+
Press enter. Your browser should now look like this:
53+
<img src="img/browser_console.png" alt="image of browser console with console.log"></img>
54+
55+
Congrats, you just wrote your first lines of JavaScript code! __console.log__ is an important function –
56+
it allows you to print information to the browser's console. It's very helpful in debugging! You can also
57+
use the __alert__ function to make a message pop up in the browser. Try it out!
58+
MARKDOWN
59+
end
60+
61+
step do
62+
message "Next try some simple math that's built into JavaScript. Type these lines into console:"
63+
64+
source_code :javascript, <<-JAVASCRIPT
65+
3 + 3
66+
7 * 6
67+
JAVASCRIPT
68+
end
69+
70+
step do
71+
message "**Variables** are names with values assigned to them."
72+
73+
source_code :javascript, <<-JAVASCRIPT
74+
var myVariable = 5
75+
JAVASCRIPT
76+
77+
message "This assigns the value `5` to the name `myVariable`."
78+
end
79+
80+
step do
81+
message "You can also do math with variables:"
82+
source_code :javascript, <<-JAVASCRIPT
83+
myVariable + 2
84+
myVariable * 3
85+
JAVASCRIPT
86+
end
87+
88+
step do
89+
message "Variables can also hold more than just numbers and text. Another type of data in Javascript is called an **array**."
90+
91+
source_code :javascript, 'var fruits = ["kiwi", "strawberry", "plum"]'
92+
message <<-MARKDOWN
93+
Here we're using the variable `fruits` to hold a collection of fruit names.
94+
An array, designated by the `[ ]` (square-brackets), is a list of data that can be referenced by its index.
95+
The index is the position inside the array, each separated by a comma. Arrays use 0-based indices, so the first element in an array is at Index 0, the second is at index 1, and so on.
96+
For example, in the array above, to get the string 'strawberry' in Javascript, you would type 'fruits[1]', which Javascript understands as: get the value at index 1 in the array fruits.
97+
MARKDOWN
98+
end
99+
100+
step do
101+
message "Arrays are a type of __object__ in JavaScript that are designated by the use of square brackets. Objects of all types in javascript often include helpful attributes!"
102+
103+
source_code :javascript, <<-JAVASCRIPT
104+
fruits.length
105+
JAVASCRIPT
106+
107+
message <<-MARKDOWN
108+
Objects can also have __functions__, which can be helpful for altering objects and learning more about them.
109+
Functions are __invoked__ with parentheses, which causes them to run.
110+
MARKDOWN
111+
112+
source_code :javascript, <<-JAVASCRIPT
113+
fruits.push("orange")
114+
fruits.slice(1)
115+
JAVASCRIPT
116+
117+
message <<-MARKDOWN
118+
The __push__ function allows us to add new items to an array. the slice function returns a new array with
119+
with everything to the right of the __index__ we provided. Here, we passed the function the number 1, so
120+
slice returned an array with everything after the first element in the array. (Note that the first element is assigned 0 as its index rather than 1).)
121+
MARKDOWN
122+
end
123+
124+
step do
125+
message "You can also make your own functions:"
126+
127+
source_code :javascript, <<-JAVASCRIPT
128+
var pluralize = function(word) {
129+
return word + "s"
130+
}
131+
pluralize("kiwi")
132+
JAVASCRIPT
133+
134+
message "Functions take **parameters**, which are the variables they work on. In this case, we made a function called pluralize that takes one parameter, a word."
135+
136+
message "Functions can also return data. In this case, pluralize returns the word with an 's' added to the end of it. In order for a function to return something, you have to use the __return__ keyword."
137+
end
138+
139+
140+
step do
141+
message "Arrays have a function called **forEach** which iterates through the list running code on each item. It takes another function as a parameter."
142+
source_code :javascript, <<-JAVASCRIPT
143+
fruits.forEach(function(fruit) {
144+
console.log(fruit)
145+
})
146+
JAVASCRIPT
147+
message "This takes the first item from the `fruits` array (`\"strawberry\"`), assigns it to the variable `fruit`, and runs the code between curly brackets. Then it does the same thing for each other item in the list. The code above should print a list of the fruits."
148+
end
149+
150+
step do
151+
message "A **conditional** runs code only when a statement evaluates to true."
152+
153+
source_code :javascript, <<-JAVASCRIPT
154+
if(myVariable > 1) {
155+
console.log('YAY')
156+
}
157+
JAVASCRIPT
158+
159+
message "This prints `YAY!` if the value stored in `myVariable` is greater than 1."
160+
161+
message "Try changing the `>` in the conditional to a `<`."
162+
end
163+
164+
end
165+
166+
next_step "lesson-2"

0 commit comments

Comments
 (0)