JavaScriptlings is an interactive learning tool designed to help users learn basic JavaScript concepts by solving small, self-contained exercises. Inspired by Rustlings, it leverages existing JavaScript task files and their corresponding Vitest test files to guide users through the learning process.
Each exercise consists of a JavaScript file in the tasks/ directory and a test file in the tests/ directory. Users are expected to modify the JavaScript task files to solve the problems. The javascriptlings CLI tool then runs the tests to verify the solutions.
To run JavaScriptlings and check your progress, use the following command:
npm run javascriptlingsThis command will:
- Discover all test files in the
tests/directory. - Determine the status of each exercise:
- SKIPPED: If the main
describeoritblocks within the test file are commented out. The tool will provide a hint on how to enable the exercise. - ATTEMPTED: If the test blocks are uncommented. The tool will then run the corresponding tests.
- SKIPPED: If the main
- Report the results for each exercise as
PASS,FAIL, orSKIPPED.
- Navigate to a Test File: Go to a test file in the
tests/directory (e.g.,tests/basics/1.even-numbers.test.js). - Uncomment the Test Block(s): Uncomment the
describeoritblocks that are currently commented out. This signals to thejavascriptlingstool that you are ready to attempt this exercise. - Implement the Solution: Open the corresponding JavaScript task file in the
tasks/directory (e.g.,tasks/1.basics/1.even-numbers.js) and write your solution. - Run JavaScriptlings: Execute
npm run javascriptlingsagain to check if your solution passes the tests. - Iterate: If the tests fail, refine your solution and re-run the tool until all tests pass.
tasks/: Contains the JavaScript files for each exercise that users need to complete.tests/: Contains the Vitest test files for each exercise. These files are used by thejavascriptlingstool to verify solutions.src/runner.js: The core CLI tool that orchestrates the exercise running and reporting.
To maintain consistency and readability across the project, please adhere to the following coding standards:
- Language: JavaScript (ES Modules).
- Formatting: Follow the existing formatting conventions within the
tasks/andtests/directories. Use consistent indentation (2 spaces preferred if not already established), spacing, and line breaks. - Naming Conventions:
- Variables and Functions: Use
camelCase(e.g.,myVariable,calculateSum). - Constants: Use
UPPER_SNAKE_CASEfor global constants (e.g.,MAX_VALUE). - File Names: Use
kebab-casefor file names (e.g.,even-numbers.js).
- Variables and Functions: Use
- Imports/Exports: Use ES Module syntax (
import ... from '...'andexport ...). - Comments: Use comments to explain complex logic or non-obvious parts of the code. Avoid excessive commenting for self-explanatory code.
- Testing: All tests are written using
vitest. Ensure new tests follow the existingvitestpatterns (describe,it,expect). - Error Handling: Implement appropriate error handling where necessary, especially for functions that might encounter unexpected input or external issues.