Code playground worksheet

Name: ____________________________   Date: ______________

Open digitalbuilders757.com/university/study/playground, choose each starter, do the task and press Run. Write down what you changed and what happened.

  1. 1. Your first web page HTML

    From the guide: HTML and CSS basics: how a web page is built

    Task: Change the heading to your name, add a second paragraph, and add a third item to the list.

    <h1>Hello, I'm learning to code</h1>
    <p>This page is made of HTML tags. Change the words and press Run.</p>
    <ul>
      <li>Headings use h1 to h6</li>
      <li>Paragraphs use p</li>
    </ul>
    

    What I changed, and what happened:

  2. 2. Style a card with CSS HTML

    From the guide: HTML and CSS basics: how a web page is built

    Task: Give the card a background colour, round its corners with border-radius, and make the button bigger with padding.

    <style>
      .card {
        max-width: 320px;
        padding: 16px;
        border: 2px solid #1f2937;
        font-family: system-ui, sans-serif;
      }
      .card h2 {
        margin: 0 0 8px;
      }
    </style>
    
    <div class="card">
      <h2>Maya's Bakery</h2>
      <p>Fresh bread every morning.</p>
      <button>Order now</button>
    </div>
    

    What I changed, and what happened:

  3. 3. Lay out boxes with flexbox HTML

    From the guide: HTML and CSS basics: how a web page is built

    Task: Centre the boxes with justify-content: center, then stack them on top of each other with flex-direction: column.

    <style>
      .row {
        display: flex;
        gap: 12px;
        font-family: system-ui, sans-serif;
      }
      .box {
        padding: 16px;
        background: #e0e7ff;
        border-radius: 8px;
      }
    </style>
    
    <div class="row">
      <div class="box">One</div>
      <div class="box">Two</div>
      <div class="box">Three</div>
    </div>
    

    What I changed, and what happened:

  4. 4. A responsive card grid HTML

    From the guide: CSS layout: flexbox, grid and fitting every screen

    Task: Change the columns to repeat(auto-fit, minmax(120px, 1fr)), then narrow your browser window and watch the cards wrap. Finally, make the first card span two columns with grid-column: span 2.

    <style>
      .cards {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
        font-family: system-ui, sans-serif;
      }
      .card {
        padding: 16px;
        background: #fef3c7;
        border-radius: 8px;
      }
    </style>
    
    <div class="cards">
      <div class="card">Tea</div>
      <div class="card">Cake</div>
      <div class="card">Soup</div>
      <div class="card">Salad</div>
      <div class="card">Pie</div>
      <div class="card">Juice</div>
    </div>
    

    What I changed, and what happened:

  5. 5. Stop the sideways scroll HTML

    From the guide: CSS layout: flexbox, grid and fitting every screen

    Task: The banner is wider than the frame, so the page scrolls sideways, just like on a phone. Change width: 1200px to max-width: 1200px and run it again.

    <style>
      body {
        font-family: system-ui, sans-serif;
      }
      .banner {
        width: 1200px;
        padding: 16px;
        background: #dcfce7;
        border-radius: 8px;
      }
    </style>
    
    <div class="banner">
      Welcome! This banner is 1200px wide, so on a phone
      it pokes out past the screen and the whole page
      scrolls sideways.
    </div>
    

    What I changed, and what happened:

  6. 6. A button that counts HTML

    From the guide: JavaScript in the browser: events and the DOM

    Task: Click the button and watch the output. Then add a second button that resets the count to 0.

    <button id="like">Likes: 0</button>
    
    <script>
      const button = document.querySelector("#like")
      let likes = 0
    
      button.addEventListener("click", () => {
        likes = likes + 1
        button.textContent = "Likes: " + likes
        console.log("Clicked! Likes are now", likes)
      })
    </script>
    

    What I changed, and what happened:

  7. 7. Check a form before it sends HTML

    From the guide: JavaScript in the browser: events and the DOM

    Task: Type an age and press Check. Then show 'Please type your age' when the box is empty, instead of treating it as 0.

    <form id="signup">
      <label for="age">Your age</label>
      <input id="age" type="number">
      <button>Check</button>
      <p id="message"></p>
    </form>
    
    <script>
      const form = document.querySelector("#signup")
      const message = document.querySelector("#message")
    
      form.addEventListener("submit", (event) => {
        event.preventDefault()
        const age = Number(document.querySelector("#age").value)
        console.log("Age typed:", age)
        message.textContent = age >= 13 ? "Welcome!" : "Ask a parent or guardian to help you sign up."
      })
    </script>
    

    What I changed, and what happened:

  8. 8. Error messages people can fix HTML

    From the guide: Forms that work: labels, checks and safe sending

    Task: Submit it empty, then with just 'sam'. The error only says 'Wrong!'. Make it say how to fix it (Enter an email like name@example.com), add autocomplete="email" to the input, and try again.

    <style>
      body {
        font-family: system-ui, sans-serif;
      }
      .error {
        color: #b91c1c;
      }
    </style>
    
    <form id="signup" novalidate>
      <label for="email">Email</label>
      <input id="email" name="email" type="email" aria-describedby="email-error">
      <p id="email-error" class="error"></p>
      <button type="submit">Join</button>
    </form>
    <p id="message" role="status"></p>
    
    <script>
      const form = document.querySelector("#signup")
      const email = document.querySelector("#email")
      const error = document.querySelector("#email-error")
    
      form.addEventListener("submit", (event) => {
        event.preventDefault()
        if (!email.value.includes("@")) {
          error.textContent = "Wrong!"
          email.setAttribute("aria-invalid", "true")
          email.focus()
          return
        }
        error.textContent = ""
        email.removeAttribute("aria-invalid")
        document.querySelector("#message").textContent = "Thanks! Check your inbox."
      })
    </script>
    

    What I changed, and what happened:

  9. 9. Text, not code HTML

    From the guide: Web security basics: access checks, XSS, CORS and cookies

    Task: Add <b>hi</b> both ways: innerHTML turns it into bold, textContent shows what was typed. Now paste <img src=x onerror="document.body.style.background='pink'"> and add it with innerHTML. The page runs code someone typed. Change add() so it always uses textContent.

    <style>
      body {
        font-family: system-ui, sans-serif;
      }
    </style>
    
    <label for="comment">Comment</label>
    <input id="comment" value="<b>hi</b>">
    <button id="as-html" type="button">Add with innerHTML</button>
    <button id="as-text" type="button">Add with textContent</button>
    <ul id="comments"></ul>
    
    <script>
      const input = document.querySelector("#comment")
      const list = document.querySelector("#comments")
    
      function add(useHtml) {
        const item = document.createElement("li")
        if (useHtml) {
          item.innerHTML = input.value
        } else {
          item.textContent = input.value
        }
        list.append(item)
        console.log("Added:", input.value)
      }
    
      document.querySelector("#as-html").addEventListener("click", () => add(true))
      document.querySelector("#as-text").addEventListener("click", () => add(false))
    </script>
    

    What I changed, and what happened:

  10. 10. Test a regex JavaScript

    From the guide: Regular expressions without fear: read, test and trust them

    Task: Run it. 'abc12345xyz' passes the five-digit check: add ^ and $ so only exactly five digits pass. Then make replace() change every dash, not just the first.

    // Meant to accept exactly five digits, like a US ZIP code.
    const zip = /\d{5}/
    
    const tries = ["23510", "2351", "abc12345xyz", "23510-1234"]
    for (const text of tries) {
      console.log(text, zip.test(text) ? "passes" : "fails")
    }
    
    // Meant to turn every dash into a slash.
    console.log("2026-11-26".replace(/-/, "/"))
    

    What I changed, and what happened:

  11. 11. Loop through a list JavaScript

    From the guide: Read code like a builder (with AI as your tutor)

    Task: Print only the scores above 80, then print the average of all five scores.

    const scores = [72, 95, 88, 64, 91]
    
    for (const score of scores) {
      console.log("Score:", score)
    }
    

    What I changed, and what happened:

  12. 12. Write a function JavaScript

    From the guide: Read code like a builder (with AI as your tutor)

    Task: Add a second function, average(numbers), that uses total. Then print the average of [10, 20, 30].

    function total(numbers) {
      let sum = 0
      for (const number of numbers) {
        sum = sum + number
      }
      return sum
    }
    
    console.log(total([3, 4.5, 2]))
    

    What I changed, and what happened:

  13. 13. Transform lists with map and filter JavaScript

    From the guide: Read code like a builder (with AI as your tutor)

    Task: Use .map to add 1 to every price, then .filter to keep only prices over 5. Can you chain them into one line?

    const prices = [4, 12, 7, 20]
    
    const doubled = prices.map((price) => price * 2)
    const small = prices.filter((price) => price < 10)
    
    console.log("Doubled:", doubled)
    console.log("Under 10:", small)
    

    What I changed, and what happened:

  14. 14. Objects and JSON JavaScript

    From the guide: APIs and JSON, hands on

    Task: Add an email field and print it, then print how many hobbies Sam has using .length.

    const user = {
      name: "Sam",
      hobbies: ["coding", "football"],
    }
    
    console.log(user.name)
    console.log(user.hobbies[0])
    console.log(JSON.stringify(user))
    

    What I changed, and what happened:

  15. 15. Fix the off-by-one bug JavaScript

    From the guide: Debugging with AI: when it breaks

    Task: Run it and read the last line of output. Then fix the loop so 'Hello, undefined' disappears.

    const names = ["Ana", "Ben", "Chloe"]
    
    for (let i = 0; i <= names.length; i++) {
      console.log("Hello, " + names[i])
    }
    

    What I changed, and what happened:

  16. 16. Escape the infinite loop JavaScript

    From the guide: Debugging with AI: when it breaks

    Task: Run it: the playground stops it after 2 seconds. Add the one missing line so it counts 0 to 4 and then says Done!

    let count = 0
    
    while (count < 5) {
      console.log("Count is", count)
    }
    
    console.log("Done!")
    

    What I changed, and what happened:

  17. 17. Wait with async and await JavaScript

    From the guide: Read code like a builder (with AI as your tutor)

    Task: Add a third step that waits 300 milliseconds and prints 'Eating pizza'. What changes if you remove an await?

    function wait(ms) {
      return new Promise((resolve) => setTimeout(resolve, ms))
    }
    
    console.log("Ordering pizza...")
    await wait(500)
    console.log("Pizza is ready!")
    

    What I changed, and what happened:

  18. 18. Side by side with Promise.all JavaScript

    From the guide: Async JavaScript: promises, async and await

    Task: Run it and compare the two times. Then add failAfter(100) to the Promise.all list, and wrap that line in try/catch so it prints a friendly message instead of the error.

    function wait(ms, value) {
      return new Promise((resolve) => setTimeout(() => resolve(value), ms))
    }
    function failAfter(ms) {
      return new Promise((_, reject) => setTimeout(() => reject(new Error("Network down")), ms))
    }
    
    let start = Date.now()
    const user = await wait(300, "Sam")
    const orders = await wait(300, 3)
    const messages = await wait(300, 5)
    console.log("One after another:", Date.now() - start, "ms", [user, orders, messages])
    
    start = Date.now()
    const all = await Promise.all([wait(300, "Sam"), wait(300, 3), wait(300, 5)])
    console.log("Side by side:", Date.now() - start, "ms", all)
    

    What I changed, and what happened:

  19. 19. The forEach that doesn't wait JavaScript

    From the guide: Async JavaScript: promises, async and await

    Task: Run it: 'All done!' prints first, with 0 saved. Fix it so it prints last, with 3 saved: use for...of with await, or await Promise.all(ids.map(...)).

    function save(id) {
      return new Promise((resolve) => setTimeout(() => resolve(id), 100))
    }
    
    const ids = [1, 2, 3]
    let saved = 0
    
    ids.forEach(async (id) => {
      await save(id)
      saved++
      console.log("Saved", id)
    })
    
    console.log("All done! Saved:", saved)
    

    What I changed, and what happened:

  20. 20. A game loop: the bouncing ball HTML

    From the guide: Project: make a simple browser game

    Task: This is a game loop: update, draw, repeat. Make the ball faster, change its colour, then console.log each time it bounces.

    <canvas id="game" width="320" height="200" style="border: 1px solid #cccccc"></canvas>
    
    <script>
      const canvas = document.querySelector("#game")
      const ctx = canvas.getContext("2d")
      let x = 40
      let y = 40
      let speedX = 3
      let speedY = 2
    
      function loop() {
        x = x + speedX
        y = y + speedY
        if (x < 10 || x > canvas.width - 10) speedX = -speedX
        if (y < 10 || y > canvas.height - 10) speedY = -speedY
    
        ctx.clearRect(0, 0, canvas.width, canvas.height)
        ctx.beginPath()
        ctx.arc(x, y, 10, 0, Math.PI * 2)
        ctx.fillStyle = "tomato"
        ctx.fill()
    
        requestAnimationFrame(loop)
      }
    
      loop()
    </script>
    

    What I changed, and what happened: