Skip to content
Snippets Groups Projects
Commit 8e289030 authored by Harshvir Singh's avatar Harshvir Singh
Browse files

Upload New File

parent 461de4ed
Branches main
No related tags found
No related merge requests found
const WEATHER_CONTAINER = 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 },
{ name: 'Gjøvik', latitude: 60.7898, longitude: 10.6822}
];
function fetchWeather(location) {
fetch(`https://api.open-meteo.com/v1/forecast?latitude=${location.latitude}&longitude=${location.longitude}&current_weather=true`)
.then(response => response.json())
.then(data => {
const weather = data.current_weather;
const weatherElement = document.createElement('div');
weatherElement.classList.add('weather');
weatherElement.innerHTML = `
<h3>${location.name}</h3>
<p>Temperature: ${weather.temperature}°C</p>
<p>Windspeed: ${weather.windspeed} km/h</p>
<p>Weather Code: ${weather.weathercode}</p>
`;
WEATHER_CONTAINER.appendChild(weatherElement);
})
.catch(err => console.error('Failed to fetch weather data', err));
}
function updateWeather() {
WEATHER_CONTAINER.innerHTML = '';
LOCATIONS.forEach(location => fetchWeather(location));
}
setInterval(updateWeather, 600000);
updateWeather();
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment