-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather.html
40 lines (34 loc) · 1.4 KB
/
weather.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" type="text/css" href="styles.css" />
<title>Document</title>
</head>
<body>
<div style="background-color: aqua; height: 500px;">
<h3>Enter City</h3>
<input type="text" id="loc">
<button onclick="city()">Submit</button>
<div id="box"></div>
<script>
async function city() {
var location = document.getElementById("loc").value;
console.log(location)
let data = await fetch(`https://api.openweathermap.org/data/2.5/weather?q=${location}&appid=69fcb514f767841ee08af4292b065051`)
.then(res => res.json())
.catch((err) => {
console.log(err.message)
})
console.log(data)
var weather = document.getElementById("box");
weather.innerHTML = "Weather" + "<br>" + "Base = " + data.base + "<br>" + "Clouds =" + data.clouds.all + "<br>" + "COD =" + data.cod + "<br>" +
"DT = " + data.dt + "<br>" + "ID = " + data.id + "<br>"
+ "Temp = " + data.main.temp + "<br>" + "Temp Max = " + data.main.temp_max + "<br>" + "Temp Min = " + data.main.temp_min + "<br>";
}
</script>
</div>
</body>
</html>