| Level Navigation: 1 | 2 | 3 | 4 | 5 | 6 | Current Level: 7 | 8 | 9 | 10 |
Goal: Scale your weather app to display weather for multiple cities.
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>
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);
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.
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
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 |