-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (26 loc) · 1.34 KB
/
app.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
const API_KEY = `be03a6d971bc920ab8c31ce8adbbc136`
const form = document.querySelector(".form")
const search = document.querySelector(".search")
const getWeather = async (city) => {
const url = `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${API_KEY}&units=metric`
const response = await fetch(url);
const data = await response.json();
return displayWeather(data);
}
const displayWeather = (data) => {
console.log(data);
const{ name } = data;
const { icon, description} = data.weather[0];
const{temp,humidity} = data.main;
const{speed}= data.wind;
document.querySelector("#elem").innerText = name ;
document.querySelector(".icon").src= "https://openweathermap.org/img/wn/" + icon + ".png";
document.querySelector(".description").innerText= description;
document.querySelector(".tempTxt").innerText= temp + " °C";
document.querySelector(".humiTxt").innerText= humidity + "%";
document.querySelector(".windTxt").innerText = speed + " Km/h";
}
document.querySelector("form").addEventListener("submit", function(event){
getWeather(search.value);
event.preventDefault(); })
getWeather("durgapur");