Skip to content
Snippets Groups Projects
Commit 87ea7781 authored by Hussain Tajammal Syed's avatar Hussain Tajammal Syed
Browse files

Upload New File

parent 177187b0
Branches
No related tags found
No related merge requests found
const weatherContainer = document.getElementById('weather-container');
const locations = [
{ name: 'Tokyo', latitude: 35.6895, longitude: 139.6917 },
{ name: 'New York', latitude: 40.7128, longitude: -74.0060 },
{ name: 'London', latitude: 51.5074, longitude: -0.1278 },
{ name: 'Paris', latitude: 48.8566, longitude: 2.3522 },
{ name: 'Sydney', latitude: -33.8688, longitude: 151.2093 }
];
function fetchWeather(location) {
const url = `https://api.open-meteo.com/v1/forecast?latitude=35.6895&longitude=139.6917&current_weather=true`;
fetch(url)
.then(response => response.json())
.then(data => {
console.log(`Weather data for ${location.name}:`, data);
displayWeather(location.name, data.current_weather);
})
.catch(error => console.error('Error fetching weather data:', error));
}
function displayWeather(locationName, weather) {
let weatherCard = document.getElementById(`weather-${locationName}`);
if (!weatherCard) {
weatherCard = document.createElement('div');
weatherCard.classList.add('weather-card');
weatherCard.id = `weather-${locationName}`;
weatherContainer.appendChild(weatherCard);
}
weatherCard.innerHTML = `
<h3>${locationName}</h3>
<p>Temperature: ${weather.temperature}°C</p>
<p>Windspeed: ${weather.windspeed} km/h</p>
<p>Weather Code: ${weather.weathercode}</p>
`;
}
function updateWeatherData() {
locations.forEach(location => {
fetchWeather(location);
});
}
setInterval(updateWeatherData, 60000);
document.addEventListener('DOMContentLoaded', updateWeatherData);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment