Variables and Objects
The Big Idea
You will use what you know about variables and JavaScript data types to create a series of values and pass a set of pre-written tests. This is your first taste of test-driven development — the tests tell you exactly what to write next.
Your Roadmap
| Section | Time | Required? |
|---|---|---|
| How this kata works | 10 min | ⚑ Required |
| Test-Driven Development | 10 min | ⚑ Required |
| Code it | 45 min | ⚑ Required |
How this kata works
Make sure you are in your cloned javascript-kata folder. If you haven't run npm install yet, do that first:
npm install
Then run the tests for this kata:
npm test 1-variables-and-arrays
Open src/1-variables-and-arrays/index.js. You will see the keyword export at the bottom of the file. This allows the test file (index.test.js) to import your variables and check them.
The tests will tell you what code to write next. Run your code and read the message explaining why the code couldn't run or why the test failed. The first step is to make the first test pass. Then make the second test pass, and so on.
Test-Driven Development
This kata uses a TDD (Test-Driven Development) approach. That means:
- Run the tests — they will fail because you haven't written the code yet
- Read the error message — it tells you exactly what is expected
- Write the minimum code to make that test pass
- Run the tests again
- Repeat until all tests pass
Error messages are a good thing. They point you to exactly where the issue is and what was expected vs what actually happened. Read them carefully — they are your guide.
Code it
Write the code in index.js to make each failing test pass. When one test passes, move to the next. When you encounter an error, write the code to fix it — then repeat until there are no failing tests.
How to know you've nailed it
| Level | You can... | ||
|---|---|---|---|
| 🪨 | Intro Climb | Get the first two tests passing | ⚑ Required |
| 🧗 | Core Ascent | Get all tests passing | ⚑ Required |
| 🏔️ | Summit | Explain in your own words what each variable type is doing and why | ◎ Optional |