codex-lv2-may-2025

Level Navigation: 1 2 3 4 5 6 7 Current Level: 8 9 10

๐ŸŽฏ Challenge Part 1: Add a Button to Show Weather Data

Goal: Make weather data appear only after a button is clicked, adding interactivity to your app.


๐Ÿ“‹ What Youโ€™ll Do

  1. Add a button to your HTML that will show the weather when clicked
  2. Modify your JavaScript to wait for the button click before displaying weather data
  3. Remove the automatic weather display from your script

๐Ÿš€ Challenge Instructions

Work in your script.js and index.html files:

  1. Add a button to your HTML that will show the weather when clicked
  2. Modify your JavaScript to wait for the button click before displaying weather data
  3. Remove the automatic weather display from your script (the setText calls that run immediately)

Challenge: Figure out how to implement this yourself! Youโ€™ll need to:


๐ŸŽ“ Learning Point: What is an Event Listener?

An event listener is a function that waits for a specific action (like a button click) to happen, then runs code in response. Think of it like setting up a security camera that watches for movement - when it detects something, it triggers an alarm.

In our code, onEvent("show-weather", "click", function() { ... }) means:

This is how we make websites interactive instead of just static displays!


๐Ÿ’ก What Youโ€™ll Review


โœ… Check Your Work


๐Ÿ”— Navigation


Ready for the next challenge? Continue to Challenge Part 2: Second City Button


Level Navigation: 1 2 3 4 5 6 7 Current Level: 8 9 10