Lesson 15 ยท JS Deep Dive boss ยท about 45 minutes

๐ŸŽฎ Mini Game: The Click Shop

Ever played Cookie Clicker? Today YOU build one โ€” for your own product. This is the final boss of the JavaScript Deep Dive, and you already own every weapon it takes. No new spells. Just you, combining everything.

๐ŸŽฌ Watch first (90 seconds)

Wait... I can build a GAME?

Yes! Here's the secret nobody tells you: a clicker game is not one giant scary thing. It's four small things you ALREADY know, holding hands:

๐Ÿ’ก The game plan (this is the whole game!) Every real game โ€” Minecraft, Mario, everything โ€” is exactly this loop: player does something โ†’ variables change โ†’ screen redraws. Today you build that loop with your own hands.

๐Ÿ› ๏ธ Build it (the boss fight)

๐Ÿงช Your mission Build The Click Shop: a giant button that sells one of your product per click, a coin counter that climbs, and celebration messages that pop at 10, 25, and 50 coins. Type everything โ€” no copy-paste. Bosses respect typers.
  1. New file! In VS Code, create practice/clicker.html. A game deserves its own house.
  2. Type the skeleton you know by heart from Lesson 2: <!DOCTYPE html>, <html>, <head> with a <title>, and a <body>.
  3. Inside the body, add the game's bricks โ€” a headline, one big button, and two signs:
    <h1>๐Ÿ›๏ธ The Click Shop</h1>
    <button id="tap">Sell a Robo Sneaker!</button>
    <p id="coins"></p>
    <p id="msg"></p>
    Swap in YOUR product name! The two <p> signs start empty โ€” JavaScript will fill them.
  4. A boss button must LOOK like a boss button. In the <head>, add a <style> and use your paint skills from Lesson 5 and Lesson 6:
    <style>
      #tap {
        padding: 30px 50px;
        font-size: 28px;
        border-radius: 20px;
        background-color: gold;
        cursor: pointer;
      }
    </style>
    Make it huge. Make it silly. It should BEG to be clicked.
  5. Now the brain. At the very end of the body (before </body>), open a <script> and create the game state โ€” memory boxes from Lesson 11:
    let coins = 0;
    const messages = ["Nice!", "On fire! ๐Ÿ”ฅ", "SHOP LEGEND ๐Ÿ‘‘"];
    coins uses let because it will change a LOT. The messages array (Lesson 14) is your prize shelf โ€” spots 0, 1, and 2.
  6. Write your own spell (Lesson 13) that paints the score onto the page:
    function redraw() {
      document.getElementById("coins").textContent =
        "๐Ÿช™ Coins: " + coins;
    }
    One job only: read the box, update the sign. That's what makes it a GOOD function.
  7. Wire up the click, exactly like the 3-line spell from Lesson 8 โ€” but now the click changes a VARIABLE:
    const btn = document.getElementById("tap");
    btn.addEventListener("click", function () {
      coins = coins + 1;
    });
  8. Milestones! INSIDE that click function, right after coins = coins + 1;, add the fork in the road from Lesson 12:
    if (coins === 10) {
      document.getElementById("msg").textContent = messages[0];
    } else if (coins === 25) {
      document.getElementById("msg").textContent = messages[1];
    } else if (coins === 50) {
      document.getElementById("msg").textContent = messages[2];
    }
    Remember: === asks "exactly equal?" โ€” three lines, not one. And arrays start counting at 0!
  9. Last wiring: the screen must redraw after EVERY click, and once when the game loads (so it doesn't start blank). Add redraw(); as the LAST line inside the click function, and ALSO once at the very bottom of the script:
      redraw();   // โ† last line inside the click function
    });
    
    redraw();     // โ† once at the start, so "Coins: 0" shows right away
  10. PLAY IT. Save (โŒ˜S), open clicker.html in the browser, and click like crazy. Watch the coins climb. Hit 10 โ€” did "Nice!" appear? Keep going to 25... to 50... You are playing a game that did not exist an hour ago, because YOU invented it. ๐ŸŽ‰
โš ๏ธ If the game is broken (every game dev's daily life) Number stuck at nothing? You probably forgot the redraw(); at the bottom of the script. Number never moves? Check that redraw(); is INSIDE the click function too, and that your ids match EXACTLY (tap, coins, msg). Milestone never shows? Count your = signs โ€” comparing needs ===, three of them. And when all else fails: right-click โ†’ Inspect โ†’ Console. The red text is the browser telling you where it hurts.

๐Ÿ˜ˆ Extra credit โ€” dares for shop legends

No steps this time. Just dares. You have every tool โ€” figure it out!

๐Ÿ•น๏ธ Try it right here โ€” this preview RUNS your game!

Big news: unlike earlier lessons, this preview box has its electricity ON. Whatever you type actually RUNS. Build a mini clicker below, then click your button in the preview and watch your number climb. Then press Check my code โœ”. (One rule: never use alert() in here โ€” the preview re-runs your code on every keystroke and it would pop up nonstop!)

๐ŸŽฎ Quiz time

No peeking at the notes above โ€” trying to remember is what makes it stick!

๐Ÿ† You beat the Deep Dive!

โœ… Boss checklist

Now the victory lap: show your teacher the game โ€” let them click it! โ€” and report your favorite bug you fixed along the way. (Every game dev has a favorite bug story. It's the law.) Your teacher will record your progress and suggest what's next. Some ideas to dream about: publishing your page on the real internet, making it look great on a phone, or adding sounds to your clicker. ๐Ÿ”Š

๐Ÿ“š Want more?

โญ Best thing to read next MDN: Dynamic scripting with JavaScript โ€” the whole official JavaScript learning path from Mozilla. Here's the amazing part: after lessons 11โ€“15, you can now ACTUALLY READ it. Variables, ifs, functions, arrays, loops, events โ€” you've met them all. It's not a wall of mystery anymore; it's a map of places you've been, plus new lands to explore.