-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (28 loc) · 1.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
document.addEventListener("DOMContentLoaded", function () {
function fetchWeatherData() {
var apiKey = 'acc103e38533f2d0a9c4250366d31546';
var city = 'Delhi,IN';
fetch(`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}`)
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(data => {
// Convert temperature from Kelvin to Celsius
var temperatureInCelsius = data.main.temp - 273.15;
// Update the weatherInfo element with relevant data
document.getElementById("weatherInfo").innerHTML = `Temperature: ${temperatureInCelsius.toFixed(2)}°C, Description: ${data.weather[0].description}, Humidity: ${data.main.humidity}%`;
})
.catch(error => console.error('Error fetching data:', error));
}
fetchWeatherData();
// Set interval for auto-refresh (e.g., every 30 minutes)
setInterval(fetchWeatherData, 30 * 60 * 1000); // 30 minutes in milliseconds
});
function isValidEmail(email) {
// Use a regular expression for basic email validation
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}