These are a series of javascript exercises intended to help you learn how to document and test functions. They start very simply, but get more involved as you progress through them.
Before you start you should have a few things installed on your machine:
- NPM. To check if you have NPM, type
npm --version
in a terminal. If you get backCommand 'npm' not found, but can be installed with:
, do NOT follow the instructions in the terminal to install withapt-get
(this causes permission issues). Instead, install NPM/Node with NVM by following the instructions here. - Jasmine. Jasmine is a testing framework for Javascript. Type
jasmine -v
to check for it. If you need to install it, typenpm install -g jasmine
to do so.- you'll use
jasmine index.spec.js
to run tests for each exercise individually
- you'll use
- Clone this repo
npm install
- this installs the dependencies for
npm run test
andnpm run document
- this installs the dependencies for
- happy coding!
Exercises are grouped by difficulty level (0, 1, 2, 3). Each exercise includes 5 files:
- a markdown file with a description of the task
- an empty (or mostly empty)
index.js
, this is where you will write your code and documentation - a set of tests in
index.spec.js
sandbox.js
. this file requires your solution, and exists for debugging your functionindex.js
should only contain your function and documentationindex.spec.js
should only contain the tests- so
sandbox.js
was born! you can practice calling your solution and stepping through in the debugger
- a file called
report.txt
, test results will be written to this file bynpm run test
Each index.js
contains an empty function with an empty doc string. Before writing any code take some time to study the test cases and write the docstring. Understanding and describing the function's behavior before writing any code will set you up for success. Be sure to include:
- A full description of the function's behavior (ie. test cases, not the code you write inside the function)
- A complete list of parameters, including their types and a short description
- The return value, including it's type and a short description
- An example use case
To see what this looks like, check out 0-hello-world/index.js
. To publish your jsdoc comments to the main README open this directory in CLI and enter npm run document
.
To study one exercise go to the exercise directory in terminal and run jasmine index.spec.js
(use gitbash if you are using Windows). This will run the test file and show you the output directly in your terminal. Upon first running the tests you will find that the tests fail: this is by design! Your task is to open up the javascript file and write the code needed to get all of the tests to pass.
The first exercise, 0-hello-world
will walk you through the process in more depth.
To test and report all exercises at once, use npm run test
. This will run the tests for each exercise and write the results into each report.txt
file.