-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
77 lines (41 loc) · 1.36 KB
/
script.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
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
75
let input = document.getElementById("input");
let city = document.getElementById("city");
let date = document.getElementById("date");
let currentTemp = document.getElementById("temp");
let minMax = document.getElementById("minMax");
let weatherType = document.getElementById("weatherType");
let weatherIcon = document.getElementById("img");
let form = document.getElementById('form')
let apiInfo = {
url: "https://api.openweathermap.org/data/2.5/weather?q=",
key: "96fd261d5d12956bb522769bba17382b",
};
let getWeatherData = async (inputValue) => {
try {
let res = await fetch(
`${apiInfo.url}${inputValue}&appid=${apiInfo.key}&units=metric`
);
let data = await res.json();
console.log(data);
let { weather, main, sys, name } = data;
if(name)
{
city.innerText = name;
date.innerText = new Date().toLocaleDateString();
currentTemp.innerText = main.temp.toString().slice(0, 2) + "°c";
minMax.innerText =
Math.floor(main.temp_min) + "/" + Math.ceil(main.temp_max)+'°c';
weatherType.innerText = weather[0].main;
weatherIcon.src = `http://openweathermap.org/img/wn/${weather[0].icon}@2x.png`;
}
else{
city.innerText = 'city not found'
}
} catch (error) {
console.log(error);
}
};
getWeatherData("kolkata");
input.addEventListener('keyup',(pri)=>{
getWeatherData(input.value);
})