-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
68 lines (52 loc) · 1.96 KB
/
index.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!doctype html>
<html lang="en">
<head>
<title>Temperature Hot</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<style>
body {
background: url(images/bg-image.jpg) no-repeat;
background-size: cover;
height: 100vh;
}
</style>
</head>
<body>
<div class="container ">
<form class="col-md-6 m-auto py-5">
<div class="input-group mb-3 ">
<input id="search" serch type="text" class="form-control" placeholder="Enter a location for Weather ...">
<div class="input-group-append">
<button id="search2" type="button" class="btn btn-danger">Search</button>
</div>
</div>
</form>
<div class="weather-status text-white text-center">
<img src="https://openweathermap.org/img/wn/02d@2x.png" alt="">
<h1 id="city">Dhaka</h1>
<h2 id="temp">38.06</span>°C</h2>
<h1 class="lead">Clouds</h1>
</div>
</div>
<script>
const apiurl = 'https://api.openweathermap.org/data/2.5/weather?q=';
const apikey = 'edb0976394f9e14b797ad0a6b8c99735';
const searchBox = document.getElementById("search");
const searchBtn = document.getElementById("search2");
async function updateWeather(city){
const response = await fetch(apiurl + city +`&appid=${apikey}` );
var data = await response.json();
console.log(data)
document.getElementById("city").innerHTML = data.name ;
document.getElementById('temp').innerHTML = data.main.temp;
}
searchBtn.addEventListener("click",()=>{
updateWeather(searchBox.value)
})
</script>
</body>
</html>