Chapter 6 · Day 2 · ~12 min

Understand & Fix the Code

AI writes code fast. But you publish it, so you are responsible for it. Learn to read AI code, find bugs with free browser tools, and ask AI for fixes the smart way.

In this chapter you will

Why you should never paste code blindly

AI can write a whole web page in seconds. It feels like magic. But the AI does not see your page, it does not test it, and sometimes it guesses. If you copy its code without looking, four things can go wrong.

Hidden bugs

AI code often looks perfect but has small mistakes: a missing tag, a typo, a button that does nothing. If you don't check, your visitors find them first.

Security and privacy

Your page's code is public: anyone can right-click and choose View page source. AI might put a password or a secret key in it (like the Mistral key you use in DigiBot), and then everyone can copy it. Or it adds a form that collects emails with no protection.

You learn nothing

If you only copy and paste, you depend on AI forever. Every explanation you read makes your next project faster and easier.

You can't fix it later

Next month something breaks. If you know which part does what, you change one line. If not, you ask AI to rewrite everything, and it may break something else.

Good news: you don't need to write code. You only need to read it well enough to ask good questions. It's like reading a rental contract before you sign it: you don't need to be a lawyer, but you should know what's inside.

Read a real page, line by line

Below is a complete mini website for a film night. It has 42 lines, just like a page an AI would write for you. It uses the three languages from Chapter 1: HTML for content, CSS for style and JavaScript for actions.

Click any highlighted line (or a numbered dot) to see what it does in plain English, and what happens if you delete it.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport"
        content="width=device-width, initial-scale=1">
  <title>Film Night · Erasmus Club</title>
  <style>
    body { font-family: sans-serif; margin: 0;
           text-align: center; }
    .hero { background: #1f1140; color: white;
            padding: 40px 20px; }
    .btn { background: #f5a300; font-size: 18px;
           padding: 12px 24px; border: 0; }
    @media (max-width: 600px) {
      .hero h1 { font-size: 28px; }
    }
  </style>
</head>
<body>
  <header class="hero">
    <h1>Film Night 🎬</h1>
    <p>Friday 9 October · 19:00 · Room B12</p>
  </header>
  <section>
    <h2>Join us!</h2>
    <p>Free popcorn. Bring a friend.</p>
    <button class="btn" id="join-btn">I'm coming</button>
    <p id="message"></p>
  </section>
  <script>
    const button = document.getElementById("join-btn");
    const message = document.getElementById("message");

    function sayThanks() {
      message.textContent = "See you there! 🍿";
    }

    button.addEventListener("click", sayThanks);
  </script>
</body>
</html>
  1. <!DOCTYPE html> is always the very first line. It tells the browser: “This page uses modern HTML.” Visitors never see it.

    If you delete it: the browser switches to an old “quirks mode” from the 1990s. Sizes and spacing can suddenly look strange.

  2. Everything between <head> (line 3) and </head> (line 19) is information for the browser, not content for visitors.

    Line 4, charset="utf-8", lets the page show every letter and emoji: ü, ç, ş, é, 🎬.

    If you delete the charset line: special letters can turn into strange symbols, like ü instead of ü.

  3. This tag tells phones: “Use your real screen width.” It is split over two lines, and that's fine: HTML doesn't care about line breaks inside a tag.

    If you delete it: phones pretend to be a big desktop screen and show your page tiny and zoomed out. Your phone rules on line 15 stop working properly. Always keep this tag!

  4. The text inside <title> appears in the browser tab, in bookmarks, in search results and when you share the link. Keep it short and clear.

    If you delete it: the tab shows the file name or web address instead, for example film-night.html. It looks unfinished.

  5. On line 21, class="hero" is like a name tag on the header. On line 11, .hero (with a dot!) means “style everything that wears the name tag hero”. That's how CSS and HTML connect.

    The names must match exactly: hero, Hero and heros are three different names.

    If you delete or misspell class="hero": the header loses its dark background and white text. There is no error message. It just looks plain.

  6. A CSS rule starts with a selector (.btn = “which elements?”). Then come curly brackets { } with property: value; pairs inside.

    #f5a300 is a hex color code: a color written as 6 characters (here: amber). 18px means 18 pixels, the size of the letters.

    If you delete a ;: the browser can't tell where one pair ends and ignores the next pair. Delete the } and the rules after it can break too.

  7. @media (max-width: 600px) means: “Use the rules inside only when the screen is 600 pixels wide or less.” That's phones. Here the big title gets smaller so it fits.

    If you delete it: the page still works, but on a phone the long title may break into ugly lines or stick out of the screen.

  8. id="join-btn" (line 28) gives the button a unique name. On line 32, document.getElementById("join-btn") means “find the element with the id join-btn”.

    Class or id? Many elements can share a class (for style). An id must be used only once per page.

    If the two names don't match: JavaScript finds nothing and the button does nothing. This is one of the most common AI bugs. You'll hunt it further down!

  9. function sayThanks() { … } is a list of steps with a name. When the browser reads it, nothing happens yet. It waits until someone calls the function.

    Line 36 is the only step: put the text “See you there! 🍿” into the empty paragraph <p id="message"> from line 29.

    If you delete it: line 39 calls a recipe that doesn't exist. The Console shows a red error: sayThanks is not defined.

  10. addEventListener("click", sayThanks) means: “When someone clicks this button, run sayThanks.” An event is something that happens on the page: a click, a key press, scrolling.

    Notice: sayThanks has no () here. We hand over the recipe; the browser runs it later, at the moment of the click.

    If you delete it: the page looks exactly the same, but clicking the button does nothing.

Result · film-night.html (try the button)

New words? The Glossary explains them all in plain English.

Let AI be your teacher

You can't remember every tag, and you don't have to. When you see code you don't understand, ask AI to explain it, not to rewrite it. Copy a prompt and paste your code under it.

Prompt · explain line by line
I am a complete beginner. Explain this code line by line in simple English. For each line, tell me in one short sentence what it does. Don't change the code. [paste your code here]
Prompt · what does this part do?
What does this part of my website code do? What would happen if I deleted it? Answer in 3 to 5 short sentences for a beginner. [paste the part here]
Prompt · check that you understood
Ask me 3 simple questions about this code to check that I understand it. Ask one question at a time and wait for my answer. [paste your code here]

Shortcut in DigiBot Studio: the Explain button Open your site in DigiBot Studio and turn on Click to edit. Click the part of your page you're curious about (for example the menu or a button), then press Explain. DigiBot tells you in simple words what that part's code does. Your page doesn't change.

AI explanations can be wrong too. If something sounds strange, test it: change one small thing and look at the result. Seeing it with your own eyes is the best teacher.

Your free detective kit: browser DevTools

You met DevTools (short for developer tools) in Chapter 1. Every desktop browser has them built in. They show you the HTML, the CSS and the error messages of any page. Don't worry, you can't break anything: all changes disappear when you reload the page.

How to open DevTools

WhereHow
Windows / LinuxF12 or Ctrl + Shift + I (on some laptops: Fn + F12)
Mac⌘ Cmd + ⌥ Option + I
Chrome, Edge, FirefoxRight-click on the page → Inspect
Safari (Mac)First, once: Safari → Settings → Advanced → turn on Show features for web developers. Then ⌘ Cmd + ⌥ Option + I.
PhonePhone browsers don't have DevTools. Use a computer and the device toolbar (see below) to pretend to be a phone.

The three parts you need today

This is a pretend DevTools window, drawn for this lesson. In this version of the film night page, the AI made a few mistakes, so you can see what problems look like. Click Elements, Console and the 📱 phone icon to explore it.

film-night.html · DevTools open
<!DOCTYPE html>
▾ <html lang="en">
▸ <head>…</head>
▾ <body>
▸ <header class="hero">…</header>
▾ <section>
<h2>Join us!</h2>
<button class="btn" id="join-btn">I'm coming</button>
<p id="message"></p>
Styles
.btn {
background: #f5a300;
colr: #1f1140;unknown property name
font-size: 18px;
}

Elements shows your page's HTML as a tree. Click a line and that part lights up blue on the page. Below it, Styles shows the CSS for that element. A crossed-out line with ⚠️ means the browser didn't understand it. That's often a typo!

Try it now (1 minute) Press F12 on this page. Click Console: are there red lines? Then click the phone icon to see this page as a phone. Press F12 again to close DevTools.

Common AI mistakes (and how to spot them)

AI predicts code that looks right. It doesn't run it, and it also learned from lots of old code on the internet. These are the mistakes you will meet most often.

MistakeWhat you noticeHow to fix it
🏷️ Missing closing tag The layout suddenly breaks: boxes inside boxes, or everything after one point is bold or a link. Ask AI: “Check that every tag is closed.” Or paste your code into the free checker at validator.w3.org.
✏️ Misspelled CSS property or color backround, colour, #ff00zz: the style simply doesn't appear. No error message! DevTools → Elements → Styles shows the line crossed out with ⚠️. CSS uses American spelling: color, center.
🔗 HTML and JavaScript use different ids A button does nothing. The Console says Cannot read properties of null. Make id="…" and getElementById("…") exactly the same, letter by letter.
🖼️ Wrong file or image path A broken image icon, or styles are missing. The Console says 404 (Not Found). Check the folder, the spelling and capital letters: Photo.JPG ≠ photo.jpg. Upload the image together with your page.
📱 Too wide on phones The page scrolls sideways on a phone. Text is cut off. Look for fixed widths like width: 1200px. Ask AI to use max-width: 100%. Test with the device toolbar.
🎭 “Fake” features A contact form says “Message sent!” but nothing arrives. A “login” with the password written in the code. Ask: “Does this really send data anywhere?” A single HTML page can't send email by itself. Use a simple mailto: email link instead.
🕰️ Outdated code Old tags like <center>, <font> or <marquee>, or tables used for page layout. Ask for “modern HTML5 and CSS (flexbox or grid), no outdated tags”.
🧩 Placeholders left in “Lorem ipsum” text, links that go to #, example.com, a fake phone number. Search your code (Ctrl + F) for #, lorem and example, and replace them with real information.

Find the bug: be the detective 🕵️

Each mini page below has one planted bug. Change the code in the dark editor: the preview updates while you type. Stuck? Press Hint. Still stuck? Press Show the fix. When you think you've got it, press Check my fix.

Bug 1 The button does nothing

Expected: click “Count me in!” and a green thank-you message appears.

Actual: nothing happens at all.

Bug 2 The card has no style

Expected: a dark purple card with white text.

Actual: plain dark text on a light background.

Bug 3 The boxes are inside each other

Expected: three boxes of the same size, side by side, and a line of text below them.

Actual: one big box with the two other boxes stuck inside it.

How to report a bug to AI

“It doesn't work, fix it” is the worst prompt in the world. The AI has to guess, and it often guesses wrong or rewrites your whole page. Give it five facts instead.

❌ Vague

My button doesn't work. Fix it.

Which button? What should happen? Any error? The AI can only guess.

✅ Clear

What I wanted: clicking "Count me in!" shows a thank-you message.
What happened: nothing happens when I click.
Error (Console): Cannot read properties of null (reading 'addEventListener')
The code: [the button line and the script]
What I tried: I reloaded the page.
Template · bug report for AI
I'm a beginner building a one-page website. Please help me fix a bug. What I wanted: [e.g. When I click "Count me in!", a thank-you message appears.] What happened instead: [e.g. Nothing happens when I click the button.] Error message (copied from the Console): [paste the red text here, or write "none"] The part of the code: [paste only the lines that belong to the problem] What I already tried: [e.g. I reloaded the page and checked the spelling.] Please explain the cause in simple words, then show me only the lines I need to change.

Two golden rules Paste only the part of the code that matters (plus a few lines around it): huge pastes make answers worse. And ask for “only the lines I need to change”, so the AI doesn't rewrite the parts that already work.

Quick check

Your “Send” button does nothing, and the Console says: Cannot read properties of null (reading 'addEventListener'). What is the most likely cause?

You wrote colour: red; in your CSS. What happens?

The AI made a contact form that says “Thanks! Message sent.” Your site is a single HTML file on free hosting. What should you do?

Your turn (5 minutes)

  1. Open your own site in DigiBot Studio (or build a quick one).
  2. Turn on Click to edit, pick one part of your page and press Explain. Did you learn something new?
  3. Download your page (the ⬇ .html button above the preview) and open the file in your browser. Press F12 and look at the Console. Any red errors? Switch to phone view. Does anything stick out?