Concept Explanation
This lesson gives the learner a simple debugging situation: the code should do something small and predictable, but something about the setup or logic needs attention. The aim is to build the habit of checking assumptions step by step instead of guessing. In a first debugging lesson, the learner should see how to read the code, run it, inspect the result, and make one focused fix. That process matters more than the size of the example.
Where to Put the Code
- Define color and position variables at the top.
- Create shape drawing or placement logic in the middle.
- Render output (print, canvas, SVG, or styled block) at the end.
Command Reference
- Run the program as written, then replace the input with a valid number and compare the result.
- Identify which line can fail and explain why the current input triggers the catch block.
- Use the example to practice reading input, converting it, and handling one expected failure cleanly.
- Make one focused fix, rerun the code, and confirm that the program now follows the expected path.
Step-by-step Guide
- Run the example once and read the output before editing anything.
- Locate the value that causes the problem and explain why parsing fails.
- Replace the input with a valid number so the success path can be tested too.
- Keep the catch block, but make the message clearer for a beginner reading the console.
- End with a quick check that both the valid and invalid inputs behave as expected.
Practice Exercises
- Create a similar example that parses an age value instead of a lesson count.
- Write a version that handles two test inputs: one valid and one invalid.
- Rewrite the example with clearer variable names while preserving the same behavior.
Coding Challenges
- Add a second validation rule so the code also rejects negative numbers.
- Compare int.Parse with a safer alternative and explain which one is friendlier in beginner code.
Mini Practice Tasks
- Rename one variable to make the bug easier to understand.
- Test the code with one numeric value and one broken value.
- Write a one-line note describing what was wrong in the original input.
Common Mistake
Mixing x and y axes or using wrong coordinate origin causes shapes to appear in unexpected places.
Real-life Mini Challenge
Draw one square, one triangle, and one circle, then move X marker 2 steps right and 1 step down.