Courses / Learn from zero
Review AI-written code before you trust it
Outcome: Find and correct a small logic bug, create test cases, and write a one-page review record. No untrusted code or sensitive files are needed.
Teaching examples are not claimed live model runs; review each lesson’s limits.
Download practice worksheet ↓Lesson 1: Code can look valid and still be wrong
You would test a new calculator with 2 + 3 before trusting it for a budget. AI-written code needs the same care. Suppose the task is adding two numbers:
function total(a, b) { return a - b; }
The syntax is valid but the function subtracts. total(2,3) would give -1 rather than 5. Try it: Read the symbol - aloud and state what it does. You can recognize the logic problem even before running the example.
Review question: Why is visually tidy code not necessarily correct?
It can fail on unexpected input; verify behavior against an expected output and tests.
Lesson 2: Define the intended behavior first
Without a requirement, you cannot tell whether a minus sign is a bug. State the contract: “Given two numbers, total returns their sum.” Then define the reference case total(2,3) → 5. The smallest corresponding code change is:
function total(a, b) { return a + b; }
Try it: What if the requirement had been subtraction? Then the original operator might be correct. Requirements come before criticism of the implementation.
Review question: What should be specified before asking for a review?
The function’s intended behavior, input and expected result, not just “review this code.”
Lesson 3: Test more than the happy case
Try total(0,5) → 5 and total(-2,3) → 1. In JavaScript, passing strings such as "2" and "3" can cause concatenation instead of numeric addition. Decide whether nonnumeric input is allowed and what failure behavior is required.
Keep expected and observed outcomes separate. If you haven't executed the code, do not fill in “observed” results as though you ran the test.
Review question: Why test an edge case as well as an ordinary input?
It reveals failures hidden by the happy path, such as an empty list or unsupported input type.
Lesson 4: Review the proposed change, not just the output
An assistant might rewrite twenty lines when one operator is the issue. Inspect the changed lines, dependencies, network calls, and permissions. A remote API is unnecessary for this tiny addition operation.
Try it: Compare the two versions and list the one character that changes. Explain why unrelated modifications deserve separate justification and testing.
Review question: How should a proposal to change many files for a one-line bug be handled?
Inspect its scope and justification, then prefer a minimal change that passes relevant tests.
Lesson 5: Submit a short review report
Record the task, defect, minimal fix, three numerical tests, and remaining limitations about input types. State explicitly whether this was a logical inspection or a real runtime test.
You learned: to review functionality rather than appearance and to avoid merging AI suggestions merely because they sound confident.
Review question: What makes a code review report actionable?
A reproduction, affected location, rationale, suggested fix and explicit acceptance tests.
What did you accomplish?
Finish only when you can complete the final exercise and explain each step’s outcome or limits.
Topic-specific worked final project
Practice input
A function adding two prices but one arrives as a string
Reference deliverable
Input: total("4",2). JavaScript can concatenate to "42" instead of the intended numeric 6.
Proposed fix: validate numeric types explicitly; test 4+2, 0+2 and string input.How do we judge success?
Accept only when valid numbers yield 6 and invalid types are handled explicitly.