-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
55 lines (54 loc) · 2.22 KB
/
index.html
File metadata and controls
55 lines (54 loc) · 2.22 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
<title>Weather info</title>
</head>
<body>
<div class="container">
<div class="container-data">
<input type="text" id="city" placeholder="Enter city name">
<input id="get-city" type="button" value="Get weather info" disabled>
<span id="city-name"></span>
<span id="city-date"></span>
<span id="city-temp"></span>
<span id="city-weather"></span>
<span id="city-temp-min"></span>
</div>
</div>
<script type="text/javascript" src="app.js">
</script>
<script>
const title = document.getElementById("city-name");
const button = document.getElementById("get-city");
document.getElementById('city-date').innerHTML = new Date().toLocaleString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
document.getElementById('city').addEventListener('keyup', function() {
if (document.getElementById('city').value.length > 0) {
button.disabled = false;
} else {
button.disabled = true;
}
});
button.addEventListener("click", () => {
const city = document.getElementById("city").value;
getCityData(city)
.then((data) => {
if(data.message){
return document.getElementById('city-weather').innerHTML = data.message
}
document.getElementById('city-temp').innerHTML = `${data.main.temp} °C`;
document.getElementById('city-weather').innerHTML = data.weather[0].main;
document.getElementById('city-temp-min').innerHTML = `${data.main.temp_min} °C / ${data.main.temp_max} °C`;
title.innerHTML = `${city}, ${data.sys.country}`;
})
.catch((error) => {
alert.apply("City not found");
});
});
</script>
</body>
</html>