Take a moment to think about this
This lesson combines the debugging, code review, secrets/security, testing, and git commit skills you learned across earlier chapters, and puts them all to work at once. It's harder than a beginner exercise — you're not just solving one problem, you're working through a whole workflow in sequence. You can lean on AI for help, but you're expected to review, understand, and verify every decision it makes. It's best to work through the tasks in order.
Practice Drills
Task 1: Give the AI the broken function below and prompt it with something like "explain why this crashes and fix it" — then review the diff line by line. Task 2: Find the hardcoded API key in the code sample, move it into .env, and add that to .gitignore. Task 3: Write a test case that checks the edge case (empty array) for the fixed function. Task 4: Split all of these changes into four logical units and commit them with conventional-commit style messages (don't push — just make the local commits).
Code Example
// Task 1: buggy function — crash ဖြစ်ရတဲ့ အကြောင်းရင်းကို ရှာပါ
function averagePrice(items) {
const total = items.reduce((sum, item) => sum + item.price, 0);
return total / items.length; // items ဗလာဆိုရင် NaN ပြန်လာမယ်
}
// Task 2: hardcoded secret ကို ရှာပြီး .env ထဲ ရွှေ့ပါ
const STRIPE_KEY = "sk_live_51Hxxxxxxxxxxxxxxxxxxxxxxxx";
function chargeCustomer(amount) {
return fetch("https://api.stripe.com/v1/charges", {
headers: { Authorization: `Bearer ${STRIPE_KEY}` },
method: "POST",
body: JSON.stringify({ amount }),
});
}
// Task 3: ဒီ edge case အတွက် test တစ်ခု ရေးပါ
// test("empty array should not crash", () => { ... })Your local repo history should show the bug fix, the secret removal, a test, and four commits — and no secret string left anywhere in the code.Try It in 5 Minutes
Set a 5-minute timer and focus on just Task 1 and Task 2 — if you can review the bug fix diff and move the secret into .env, that counts as a win.
A Quick Word of Caution
Never practice with a real API key — use a dummy string that just looks like a sample key when you practice the secret-removal flow.