-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
33 lines (25 loc) · 1.39 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
let key = "4ec67467a9b9f37556f4543c9a731e20";
let url = `https://api.openweathermap.org/data/2.5/weather?q=&appid=${key}&units=metric`;
// --------------------------------------------------------------------------------------------------
const getdata = async () => {
let promise = await fetch(url);
try {
let data = await promise.json();
document.getElementById("city").innerText = data.name + ", " + data.sys.country;
document.getElementById("temperature").innerText = data.main.temp + " °C";
document.getElementById("humidity").innerText = data.main.humidity + " %";
document.getElementById("weather").innerText = data.weather[0].main + " Type";
document.getElementById("clouds").innerText = data.clouds.all + " Okta";
document.getElementById("wind-speed").innerText = data.wind.speed + " Km/Hr";
} catch (error) {
alert("City Not Found!");
}
}
// --------------------------------------------------------------------------------------------------
let btn = document.getElementById('button');
let input = document.getElementById('input');
// --------------------------------------------------------------------------------------------------
btn.addEventListener("click", () => {
url = `https://api.openweathermap.org/data/2.5/weather?q=${input.value}&appid=${key}&units=metric`;
getdata();
})