-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
74 lines (69 loc) · 2.18 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
69
70
71
72
73
74
<!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">
<title>Document</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div class="api">
</div>
</div>
<section class="top-banner">
<div class="container">
<h1 class="heading">Simple Weather App</h1>
<form>
<input type="text" id="location" placeholder="Search for a city" autofocus>
<button type="button" onclick="get_api()">SUBMIT</button>
<span class="msg"></span>
</form>
</div>
</section>
<section class="ajax-section">
<div class="container">
<ul class="cities" id="cities"></ul>
</div>
</section>
<footer class="page-footer">
<div class="container">
</small>
</div>
</footer>
<script>
function get_api(){
var location = document.getElementById('location').value;
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Key': 'fc7e82c08emshd1594a18cf2578fp1584e5jsn9e00d35cc35a',
'X-RapidAPI-Host': 'yahoo-weather5.p.rapidapi.com'
}
};
var cities = document.getElementById('cities');
cities.innerHTML = "";
fetch(`https://yahoo-weather5.p.rapidapi.com/weather?location=${location}&format=json&u=c`, options)
.then(response => response.json())
.then(response => {
console.log(response);
for(var i =0; i < response.forecasts.length; i++){
cities.innerHTML+=
`<li class="city">
<h2 class="city-name" data-name="Karachi,PK">
<span>${response.location.city}</span>
<sup>${response.location.country}</sup>
</h2>
<div class="city-temp">${response.forecasts[i].high}<sup>°C</sup></div>
<figure>
<img class="city-icon" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/162656/02d.svg" alt="few clouds">
<figcaption>${response.forecasts[i].text}</figcaption>
<span>${response.forecasts[i].day}</span>
</figure>
</li>`;
}
})
}
</script>
</body>
</html>