JavaScript Coding Lessons
Learn JavaScript by writing it: 24 short lessons from console.log to recursion, each graded in your browser against real tests, with the reason every test passed or failed.
How to Use
- Lesson 1 is open with its test already listed: print
Hello, world!. Pick any of the 24 lessons from the list, or use a preset to jump to the first lesson of a level. - Read the concept (each one links to the MDN page it is based on), then do the task: write code, fix a bug, predict the output or pick an answer.
- Press Run to see what your code prints, then Check (or Ctrl+Enter) to grade it. The readouts show the lesson number, tests passed, your progress through the course and how many times you have checked this lesson.
- Read Show Work for what the grader ran for each test and why it passed or failed. Stuck? Hint gives a nudge; Reset restores the starter code.
- Press Visualize to watch the same code run line by line in the Execution Visualizer, and follow the tool links when a lesson touches a real Bunker tool.
Loading…
Worked Example
Lesson 4, the remainder operator. The task is remainder(a, b), and the grader runs 3 call tests. With return a % b; it prints 2 for remainder(17, 5) (17 = 3 × 5 + 2), 0 for remainder(10, 2) and 1 for remainder(9, 4) (9 = 2 × 4 + 1): 3 of 3 tests pass. With return a / b; the same tests print 3.4, 5 and 2.25, so 0 of 3 pass and each row reads “expected 2, got 3.4” and so on.
Lesson 16, a missing return. function double(n) { n * 2; } works out 10 for double(5) and then throws it away. With no return the call gives back undefined, which is what the test prints, so it fails with “expected 10, got undefined”. Adding return makes all 3 tests pass (10, 0 and 14).
The common mistake: lesson 14’s for (let i = 1; i < n; i++). For countTo(5) the loop stops when i reaches 5, so it returns 1,2,3,4 instead of 1,2,3,4,5; for countTo(1) the test 1 < 1 is false straight away and it returns an empty string instead of 1; countTo(3) gives 1,2. That is 0 of 3. Changing < to <= includes n and all 3 pass.
Show Work
How It Works
Background: What Each Level Teaches
Never Coded (lessons 1–4). console.log() “outputs a message to the console”. let declares “re-assignable, block-scoped local variables”, while a const “can’t be changed through reassignment”. The remainder operator % “always takes the sign of the dividend”, so -7 % 3 is −1 and 7 % -3 is 1.
Beginner (lessons 5–12). The + operator “produces the sum of numeric operands or string concatenation”: if one side is a string, the other is converted to a string, so "1" + 2 is "12". Subtraction converts both operands to numbers, so "5" - 1 is 4. Strict equality “always considers operands of different types to be different”: 1 === "1" is false although 1 == "1" is true. A for statement has “three optional expressions”: start, test and update.
Intermediate (lessons 13–19). return “ends function execution and specifies a value to be returned”; if the value is omitted, undefined is returned, which is exactly the lesson 16 bug. map() “creates a new array populated with the results of calling a provided function on every element”, and push() adds elements to the end of an array and returns its new length.
Advanced (lessons 20–24). Recursion is “the act of a function calling itself”, with a base case that ends it and a recursive case that continues it. Leave the base case out and JavaScript throws “too much recursion” or “Maximum call stack size exceeded”, the error for “too many function calls, or a function … missing a base case”.
All quotations are from MDN Web Docs (the console.log(), let, const, Remainder, Addition, Subtraction, Strict equality, for, return, Array.prototype.map(), Array.prototype.push() and Recursion pages, and the “too much recursion” error reference); each lesson links to its page. JavaScript itself was conceived by Brendan Eich at Netscape and shipped in Netscape Navigator 2.0 in September 1995 (MDN), and the first edition of its standard, ECMA-262, is dated June 1997 (Ecma International).
About This Tool
These are 24 short JavaScript lessons in four kinds: 11 where you write code, 4 where you fix a bug, 5 where you predict what code prints and 4 quick multiple-choice checks. They run from a first console.log to recursion and the cost of algorithms, and every lesson’s reference answer is checked to pass while its starter code and a typical wrong answer fail.
Most course sites tell you only pass or fail. Here Show Work says what each test ran, what your code printed and why it did not match, and Visualize opens the same code in the step-by-step visualizer. The grading runs in your browser and nothing you write is uploaded; progress is kept in this browser only.
It is for complete beginners, for self-taught programmers filling gaps (type coercion, off-by-one loops, missing returns), and for teachers who want a link to one exercise such as ?lesson=fixbug-offbyone.
Related tools: Number Base Converter, JSON Formatter, and URL Slug Generator.
Frequently Asked Questions
How is my code graded?
Your code runs in the Code Lab interpreter, the same engine as the Execution Visualizer, once per test. A call test adds one line, console.log(call), and compares the last printed line with the expected text: remainder(17, 5) must print 2. An output test compares everything your program printed. Nothing is uploaded.
My answer looks right but fails. Why?
The comparison is exact text. Printing Hello world instead of Hello, world! fails, and so does a function that computes n * 2 but never returns it: it gives back undefined. Show Work names the reason for each failed test, such as “nothing was printed” or “the function gave back undefined”.
What if my code loops forever or recurses without stopping?
The interpreter stops after 5,000 steps and the test fails with “Stopped after 5000 steps”. A recursive function with no working base case overflows the call stack instead; the grader reports that once and does not run the remaining tests again with the same code.
Is my progress saved?
Yes, on this device only. Completed lessons, your code for each lesson and your attempt counts are kept in this browser’s local storage, so the course progress readout (for example 5 / 24) is still there next time. Clearing site data resets it.
Are there Python lessons?
Not yet. All 24 lessons are JavaScript. Python already works in the Execution Visualizer and the Code Inspector, which run a teaching subset of it; Python lessons are planned and the Code Lab marks them “Coming soon”.
How do I use the JavaScript Coding Lessons?
Simply type your numbers and read the result, which refreshes the instant you change something. There is nothing to submit and nothing to wait for.
Is it free? Does it work without internet?
Yes to both. It is free with no sign-up, and once the page has loaded it keeps working even with no internet.
Where does my data go?
Nowhere — every calculation runs on your own device. Nothing you enter is uploaded, logged, or stored.
Common Use Cases
First program
Lesson 1 asks for one line, console.log("Hello, world!"), and passes when exactly that text is printed.
Spot type coercion
Lesson 7 asks what "1" + 2 and "5" - 1 print: 12 and 4, because + joins strings while - always does maths.
Find an off-by-one bug
Lesson 14 loops with i < n, so countTo(5) gives 1,2,3,4; changing it to i <= n passes all 3 tests.
Practise recursion
Lessons 20 to 24 cover factorial (5! = 120), a recursive countdown, a wrong base case in power(2, 10) and Fibonacci (fib(10) = 55).
Classroom warm-up
Send ?lesson=fixbug-return so a class starts on the missing-return bug, where double(5) gives undefined instead of 10.
Last updated: