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. - Clone this repo
npm install
- happy coding!
Exercises are grouped by difficulty level (0, 1, 2, 3). Each exercise includes 4 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
- 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 complete the exercise go to the exercise directory with cd exercise-name
in a terminal and run jasmine index.spec.js
. This should find and run the test file and show you the output. 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.