Learning to Program: Getting Started by Scott Allen
The best way to learn is to follow along with Scott, entering the code as he demonstrates each example.
Variables and Types
In the second module, Scott teaches text editors and code files, starting with Notepad and programming “pizza” and “fish and chips”, and moving on to Notepad++. The var keyword and semicolons are introduced in the “syntax rules” clip. Then in the “when to panic” clip we learn how to create, read and diagnose some common error messages.
Then we see the first potentially useful program: taking the number of people in a party and calculating their bill for their piece of a pizza.
The following module covers variable declarations and types. Scott shows that a variable returns undefined if the type is not set, and creates an “x is not defined” error.
Scott explains the parseInt function for converting to numbers, and shows a writeGreeting function.
Scott writes a roll the dice game which outputs two random numbers between 1 and 6 (representing die values) and sums them together. This covers math functions such as rand and ceil, and the code is wrapped into our own function.
Then the example is enhanced to support different dieSize, for example if we can simulate seven sided die, or any other number of sides.
In the scope clip Scott explains that local variables can only be accessed inside a function, but global variables can be accessed from anywhere.
Branches and loops
Covers if statements, several operators including and (&&), or (||) and not (!), else blocks,
and then while loops and do while loops. Also, for loops and arrays.
After explaining what objects are and how to create them, Scott demonstrates splitting programs into multiple files, and using the exports and require keywords in Node.js to read data from other files.
The example used in this module is a grade book. Scott downloads nodeunit from NPM. I had not seen this unit testing framework before, based on the version covered in this course it seems quite basic but is enough to cover the most common scenarios.
Credit to Scott for covering Test Driven Development (TDD) in a beginners course. Often it is described as an “advanced” technique, but Scott shows that it is actually quite straightforward. In the second test we see a flawed test that is not doing what we first might think it is. Assigning a function to exports[“setUp”] which reinitializes the object that we are testing, is the fix for our unit tests.
In this last module, the grade book is enhanced to assign letter grades (e.g an average score of 90-100 is an A). This is done using TDD again, although Scott challenges you to write the tests for grades B, C, D and F.
Next, Scott introduces Express JS, a very popular web framework for Node JS. This is easily installed by typing the following into the Node console window:
npm install express
Scott begins with a hello world message, which displays in the browser. Then he adds a command for running the grades program using user inputted scores. The example displays:
Your average is 91.25 grade A
Children and adult beginners – 1.0x
Experienced amateurs – 1.5x
Pros new to JS – 2.0x
JS Pros – 2.0x and skip at least the first few modules