codex-lv2-may-2025

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

βœ… Step 7: Create Multi-City Weather Pages

Goal: Scale your weather app to display weather for multiple cities.


πŸ“‹ What You’ll Do

  1. Create HTML files for additional cities (Atlanta, Seattle, your chosen city)
  2. Create JavaScript files for each city’s weather logic
  3. Build Bootstrap cards for each city
  4. Use the same helpers.js across all pages

πŸš€ Step-by-Step Instructions

1. Create City HTML Files

For each city, create a new HTML file (e.g., atlanta.html, seattle.html):

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Atlanta Weather</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div class="container mt-4">
        <h1>Atlanta Weather</h1>
        
        <div class="card" style="width: 18rem;">
          <div class="card-body">
            <h5 class="card-title">Atlanta Weather</h5>
            <p class="card-text">
              Temperature: <span id="temp"></span>Β°C<br>
              Wind Speed: <span id="wind"></span> km/h<br>
              Weather Code: <span id="code"></span>
            </p>
          </div>
        </div>
        
    </div>

    <script src="helpers.js"></script>
    <script src="atlanta-script.js"></script>
</body>
</html>

2. Create City JavaScript Files

For each city, create a script file (e.g., atlanta-script.js):

// Atlanta weather data POJO
var atlantaWeather = {
  "latitude": 33.75,
  "longitude": -84.39,
  "current_weather": {
    "temperature": 28.5,
    "windspeed": 6.2,
    "weathercode": 0
  }
};

// Display Atlanta weather data
setText("temp", atlantaWeather.current_weather.temperature);
setText("wind", atlantaWeather.current_weather.windspeed);
setText("code", atlantaWeather.current_weather.weathercode);

3. Repeat for Other Cities


πŸ’‘ What This Accomplishes

Expanding your weather app to multiple cities demonstrates how to scale a project and manage multiple files effectively. This step teaches you about project organization, code reuse, and how to maintain consistency across similar pages. It also shows how the skills you learned for one city can be applied systematically to create a comprehensive multi-city weather application.


πŸ“ Final File Structure

my-weather/
β”œβ”€β”€ index.html              ← New Orleans (main page)
β”œβ”€β”€ script.js               ← New Orleans weather logic
β”œβ”€β”€ atlanta.html            ← Atlanta weather
β”œβ”€β”€ atlanta-script.js       ← Atlanta weather logic
β”œβ”€β”€ seattle.html            ← Seattle weather
β”œβ”€β”€ seattle-script.js       ← Seattle weather logic
β”œβ”€β”€ [city].html             ← Your chosen city
β”œβ”€β”€ [city]-script.js        ← Your city's weather logic
β”œβ”€β”€ helpers.js               ← Shared helper functions
└── README.md

βœ… Check Your Work


πŸ”— Navigation


Ready for challenges? Continue to Challenge Part 1: Add a Button


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