العربية

Module 3: Prompt Engineering

Course: Programming with Free AI Tools — Build Real Websites and Apps | Audience: Ages 15–25, beginners | Module Goal: Write clear, effective prompts for code generation, debugging, and explanations. Learn bad vs good prompt examples.

Teaching Principle: A vague prompt gets a vague answer. Be specific, give context, and ask for verification steps.

Table of Contents

Lesson 3.1 — Anatomy of a Good Prompt

Duration: 50 minutes

Learning Objectives

Instructor Notes

Use the "bad vs good" contrast heavily. Show that adding language, experience level, and output format dramatically improves results. Encourage students to iterate.

Presentation Outline

  1. Why prompts matter (5 min).
  2. The 4-part prompt formula (15 min).
  3. Bad prompt vs good prompt examples (15 min).
  4. Live rewrite activity (10 min).
  5. Practice and feedback (5 min).

Demonstration

  1. Show bad prompt: "Make a website."
  2. Show AI's vague answer.
  3. Show good prompt: "Act as a web teacher. Write a single HTML page for a bakery with a title, one heading, and a paragraph. Output only the HTML code with comments."
  4. Show the clear, usable answer.
  5. Run the HTML to verify.

AI Prompts

Starter Code

Bad prompt:
"make a button"

Good prompt (fill in):
Role: ___________________
Task: ___________________
Context: ___________________
Format: ___________________

Final Code

Good prompt example:
Role: Act as a front-end teacher for beginners.
Task: Create an HTML button that shows an alert "Hello" when clicked.
Context: Plain HTML file, no frameworks, for a 16-year-old learner.
Format: Output only the HTML code with short comments.

Exercises

Homework

Quiz

  1. Which is part of a strong prompt?
    • a) Role
    • b) Task
    • c) Context
    • d) All of the above ✅
  2. A vague prompt usually gives:
    • a) Perfect code
    • b) A vague or generic answer ✅
    • c) Nothing
    • d) An error message only
  3. Adding "for a beginner" to a prompt helps because:
    • a) It makes the AI slower
    • b) It sets the explanation level ✅
    • c) It is required
    • d) It changes the language
  4. Good prompts often specify:
    • a) Output format ✅
    • b) The weather
    • c) Your birthday
    • d) A random number
  5. The best way to improve an answer is to:
    • a) Repeat the same vague prompt
    • b) Add context and constraints, then iterate ✅
    • c) Give up
    • d) Shout

Lesson 3.2 — Prompting for Code Generation

Duration: 50 minutes

Learning Objectives

Instructor Notes

Teach students to specify the language and any libraries. Ask for small, runnable examples. Always end with "explain how to run this." Show a generated snippet running successfully.

Presentation Outline

  1. Recap prompt anatomy (5 min).
  2. Specifying language and framework (10 min).
  3. Asking for comments and run instructions (10 min).
  4. Live code generation demo (15 min).
  5. Verification routine (10 min).

Demonstration

  1. Prompt: "Act as a JS teacher. Write a function `isEven(n)` returning true if n is even. Include a comment and one example usage. Output only code."
  2. Copy into a file, run with Node or browser console.
  3. Show the output is correct.
  4. Modify the prompt to add edge cases and regenerate.

AI Prompts

Starter Code

// Starter: generate with AI, then verify
function isEven(n) {
  // TODO: return true if n is even
}

Final Code

// Final
function isEven(n) {
  return n % 2 === 0; // even numbers have no remainder when divided by 2
}

console.log(isEven(4)); // true
console.log(isEven(7)); // false

Exercises

Homework

Quiz

  1. When generating code you should specify:
    • a) The programming language ✅
    • b) The color of your room
    • c) Your favorite food
    • d) None of these
  2. Asking for comments helps you:
    • a) Waste tokens
    • b) Understand the generated code ✅
    • c) Break the code
    • d) Hide errors
  3. After generating code you must:
    • a) Submit immediately
    • b) Run and verify it ✅
    • c) Delete it
    • d) Ignore output
  4. A precise prompt includes:
    • a) Framework and constraints ✅
    • b) Emojis only
    • c) One word
    • d) A joke
  5. "Output only code" is useful because:
    • a) It confuses the AI
    • b) It gives clean, copy-ready output ✅
    • c) It is required
    • d) It slows things down

Lesson 3.3 — Prompting for Debugging

Duration: 50 minutes

Learning Objectives

Instructor Notes

Teach the "error + code + what you expected" formula. Show that AI may guess; students must test. Use a real broken snippet live.

Presentation Outline

  1. Why debugging with AI works (5 min).
  2. The debugging prompt formula (10 min).
  3. Bad vs good debugging prompts (10 min).
  4. Live debug demo (15 min).
  5. Verify-the-fix routine (10 min).

Demonstration

  1. Show broken code: `print("Hello"` (missing parenthesis).
  2. Bad prompt: "fix." Show weak answer.
  3. Good prompt: "This Python code errors: `print('Hello'`. Error: SyntaxError. What is wrong and how do I fix it? Show corrected code."
  4. Run the fix; confirm it works.

AI Prompts

Starter Code

# Starter (broken): fix with AI help
def greet(name)
    print("Hello " + name)

greet("Sam")

Final Code

# Final (fixed): added missing colon
def greet(name):
    print("Hello " + name)

greet("Sam")  # Output: Hello Sam

Exercises

Homework

Quiz

  1. A good debugging prompt includes:
    • a) The error message ✅
    • b) A joke
    • c) Your address
    • d) Nothing
  2. When AI gives a fix you should:
    • a) Trust it blindly
    • b) Test it by running the code ✅
    • c) Delete the code
    • d) Ignore it
  3. "What did you expect vs what happened" helps AI because:
    • a) It wastes time
    • b) It gives context to find the real bug ✅
    • c) It is required
    • d) It changes the language
  4. A SyntaxError usually means:
    • a) The computer is broken
    • b) The code violates language grammar rules ✅
    • c) The AI is wrong
    • d) Nothing
  5. AI debugging is best used as:
    • a) A replacement for learning
    • b) A helper that still needs your verification ✅
    • c) A guarantee
    • d) A game

Lesson 3.4 — Prompting for Explanations

Duration: 45 minutes

Learning Objectives

Instructor Notes

Explaining is where AI shines for learning. Teach "explain like I'm 15" and "give an analogy." Show how to turn a confusing snippet into a clear summary.

Presentation Outline

  1. Why explanations matter (5 min).
  2. "Explain like I'm 15" technique (10 min).
  3. Asking for analogies (10 min).
  4. Summarize-code demo (10 min).
  5. Build-your-own explanation (10 min).

Demonstration

  1. Paste a loop snippet into AI.
  2. Prompt: "Explain this Python loop like I'm 15, with an analogy."
  3. Show the analogy (e.g., checking each item on a shelf).
  4. Ask: "Summarize this function in 3 bullet points." Show result.

AI Prompts

Starter Code

// Starter: ask AI to explain this
for (let i = 0; i < 3; i++) {
  console.log(i);
}

Final Code

AI explanation summary:
- The loop starts with i = 0.
- It runs while i is less than 3.
- Each run prints i, then adds 1 (i++).
Output: 0, 1, 2

Exercises

Homework

Quiz

  1. "Explain like I'm 15" is used to:
    • a) Insult the AI
    • b) Get a simple, clear explanation ✅
    • c) Slow it down
    • d) Change language
  2. An analogy helps because it:
    • a) Confuses the topic
    • b) Connects new ideas to familiar ones ✅
    • c) Is required
    • d) Breaks code
  3. Summarizing code into bullets helps you:
    • a) Forget it
    • b) Understand structure quickly ✅
    • c) Delete it
    • d) Hide bugs
  4. You should ask AI to explain code you don't understand:
    • a) Never
    • b) Yes, to build real understanding ✅
    • c) Only if paid
    • d) Only once
  5. The goal of explanation prompts is to:
    • a) Copy answers
    • b) Understand, not just receive code ✅
    • c) Entertain
    • d) Win arguments