W4Week 4 of 4 — Capstone

The Code Review

Review 3 programs from another mind. Full workflow. Real judgment calls.

The skill: All three stances together — epistemic humility, computational empathy, collaborative posture. This is what verification looks like.

Time: 8-10 hours total

This week uses: Variables · if/else · for loop · while loop · Arrays [] · Verification

Covered in Lesson 3 & Lesson 4. If any feel unfamiliar, review before continuing.

Your progress0 / 3 complete

Estimated time remaining: 8-10 hours

The Context

You've joined a team. Another mind wrote three programs. They think the code works. Your job: verify whether it actually does what was requested.

This isn't bug hunting. It's asking: does this code match its specification? Are there inputs the author didn't consider? Would you trust this to run in production?

The Workflow

  1. 1
    READ — What is this supposed to do? What inputs and outputs?
  2. 2
    TRACE — Walk through with 2 sample inputs. Does output match expectation?
  3. 3
    VERIFY — Test 3 edge cases. What inputs might break this?
  4. 4
    CRITIQUE — List all issues. Explain why each matters. Rate severity.
  5. 5
    SPECIFY — For each issue, describe what the fix should accomplish (not the fix itself).
  6. 6
    OVERALL — Ship / Ship with fixes / Needs rework. Your call.

First: See What Good Looks Like

Before you begin, study this example. Watch how the workflow reveals a mismatch between what the code does and what it should do.

Example: A Simple Doubler

The code:

function double(x) {
  return x + x;
}

// Example: double(5) returns 10

From the author: “A function that doubles a number.”

1. READ — What is this supposed to do?

Purpose: Double a number

Expected input: x (a number)

Expected output: x × 2

2. TRACE — Walk through with sample inputs

Input: x = 5

return 5 + 5 → 10

Matches expectation? YES — 5 × 2 = 10 ✓

Input: x = "hello"

return "hello" + "hello" → "hellohello"

Matches expectation? NO — expected NaN or error, got string concatenation

3. VERIFY — Test edge cases

Edge case: Very large number (Number.MAX_VALUE)

Expected: Infinity or overflow handling. Actual: Returns Infinity. Maybe OK?

Edge case: NaN

Expected: NaN. Actual: NaN. OK

Edge case: String "3" (not number 3)

Expected: 6 or error. Actual: "33" (concatenation). Issue!

4. CRITIQUE — What's wrong? Why?

Issue: Uses + instead of ×. For numbers this works (5 + 5 = 10 = 5 × 2), but + has different behavior for strings.

Why it matters: If anyone passes a string (even accidentally), the function silently produces wrong output instead of failing loudly.

Severity: Major — core functionality is ambiguous

5. SPECIFY — What should the fix accomplish?

The function should either: (a) use x * 2 to ensure numeric multiplication, or (b) validate that x is a number and throw/return error for non-numbers. Option (a) is simpler and matches intent.

6. OVERALL — Ship, fix, or rework?

Recommendation: Ship with fixes

Summary: The function works for its intended use case (numbers) but fails silently for strings. A one-character fix (+ → *) resolves the ambiguity. Low risk, quick fix.

Notice: the code “works” for the happy path. The issue only appears when you question assumptions. That questioning is the skill.

Program 1: Tip Calculator

A function that calculates tip and total bill.

1

Tip Calculator

From the AI that wrote it: “A function that calculates the tip and total bill. Takes the bill amount and tip percentage as inputs. Returns an object with the tip amount and the total.

1
2
3
4
5
6

The Code

javascript
1function calculateTip(billAmount, tipPercent) {
2 // Calculate tip
3 let tipAmount = billAmount * tipPercent;
4
5 // Calculate total
6 let total = billAmount + tipAmount;
7
8 return {
9 tip: tipAmount,
10 total: total
11 };
12}
13
14// Example usage:
15let result = calculateTip(50, 20);
16console.log("Tip: $" + result.tip);
17console.log("Total: $" + result.total);

1. READ

What is this supposed to do?

Program 2: Password Checker

A function that validates passwords against requirements.

2

Password Checker

From the AI that wrote it: “A function that validates passwords. Must be at least 8 characters, contain at least one number, and at least one uppercase letter. Returns true if valid, false if not.

1
2
3
4
5
6

The Code

javascript
1function isValidPassword(password) {
2 // Check length
3 if (password.length < 8) {
4 return false;
5 }
6
7 // Check for number
8 let hasNumber = false;
9 for (let char of password) {
10 if (char >= "0" && char <= "9") {
11 hasNumber = true;
12 }
13 }
14
15 // Check for uppercase
16 let hasUppercase = false;
17 for (let char of password) {
18 if (char >= "A" && char <= "Z") {
19 hasUppercase = true;
20 }
21 }
22
23 return hasNumber && hasUppercase;
24}
25
26// Example usage:
27console.log(isValidPassword("Secret123")); // true
28console.log(isValidPassword("password")); // false

1. READ

What is this supposed to do?

Program 3: Number Guessing Game

An interactive game where the player guesses a random number.

New syntax in this program:

  • Math.random() — returns a random decimal between 0 and 1
  • Math.floor(x) — rounds x down to the nearest integer
  • prompt(message) — shows a dialog, returns user's text input as a string
  • parseInt(str) — converts a string to an integer (e.g., "42" → 42)
3

Number Guessing Game

From the AI that wrote it: “A number guessing game. Computer picks a random number 1-100. Player guesses. Computer says higher/lower until correct. Tracks number of guesses.

1
2
3
4
5
6

The Code

javascript
1function playGame() {
2 let n = Math.floor(Math.random() * 100);
3 let g = 0;
4 let c = 0;
5
6 while (g !== n) {
7 let input = prompt("Guess a number (1-100):");
8 g = parseInt(input);
9 c++;
10
11 if (g < n) {
12 console.log("Higher!");
13 } else if (g > n) {
14 console.log("Lower!");
15 }
16 }
17
18 console.log("Correct! It took " + c + " guesses.");
19}

1. READ

What is this supposed to do?

The Takeaway

Code review is collaboration between minds across time. The original author isn't here to explain — the code must speak for itself, and you must listen. This skill transfers: when you write code, you're writing for a future reviewer. When you prompt AI, you're specifying for another mind. The same careful attention applies everywhere.