-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathweather.js
42 lines (34 loc) · 1.81 KB
/
weather.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
37
38
39
40
41
42
function weatheria() {
var city1 = document.getElementById('value').value;
var link_api = 'http://api.openweathermap.org/data/2.5/weather?q=' + city1 + '&appid=e8cde246c8e175455f7354975fd34a4a&units=metric';
fetch(link_api)
.then(
function (dat) {
if (dat.status !== 200) {
document.getElementById('distemp').innerHTML = '<br>Please enter correct city';
return;
}
dat.json().then(function (data) {
document.getElementById('distemp').innerHTML = '<p>City : ' + city1 + ' <p>Temperature : ' + (data.main.temp) + '℃</p><p>Humidity : ' + data.main.humidity + '%</p>';
document.getElementById('disimg').src = 'https://raw.githubusercontent.com/Subhash2807/Weather-App-JavaScript/master/icons/' + data.weather[0].icon + '.png';
imge(data.weather[0].main);
});
}
)
;
}
function defult() {
var link_api = 'http://api.openweathermap.org/data/2.5/weather?q=lucknow&appid=e8cde246c8e175455f7354975fd34a4a&units=metric';
fetch(link_api)
.then(
function (dat) {
dat.json().then(function (data) {
document.getElementById('distemp').innerHTML = '<p>City : Lucknow <p>Temperature : ' + (data.main.temp) + '℃</p><p>Humidity : ' + data.main.humidity + ' %</p>';
document.getElementById('disimg').src = 'https://raw.githubusercontent.com/Subhash2807/Weather-App-JavaScript/master/icons/' + data.weather[0].icon + '.png';
});
}
)
.catch(function (error) {
console.log('Fetch Error :-S', error);
});
}