-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
44 lines (38 loc) · 1.69 KB
/
index.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
const api="28f04955531a966b1b575e9cbfee84ae";
const url="https://api.openweathermap.org/data/2.5/weather?unit=metric";
const weather_i = document.querySelector(".weather_img")
async function weather(){
var city= document.getElementById("input_city").value;
const response = await fetch(url + `&appid=${api}` + `&q=${city}`);
var data = await response.json();
console.log(data);
document.getElementById("city").innerHTML=data.name;
document.getElementById("temperature").innerHTML= Math.round(data.main.temp) + "F";
document.getElementById("humidity").innerHTML=data.main.humidity + "%";
document.getElementById("wind_speed").innerHTML=data.wind.speed + "KM/Hr";
if (data.weather[0].main == "Drizzle") {
weather_i.src="images/drizzle.png";
document.getElementById("w_condition").innerHTML="Drizzle";
}
else if (data.weather[0].main == "Clear") {
weather_i.src="images/clear.png";
document.getElementById("w_condition").innerHTML="Clear";
}
else if (data.weather[0].main == "Rain") {
weather_i.src="images/rain.png";
document.getElementById("w_condition").innerHTML="Rain";
}
else if (data.weather[0].main == "Mist") {
weather_i.src="images/mist.png";
document.getElementById("w_condition").innerHTML="Mist";
}
else if (data.weather[0].main == "Clouds") {
weather_i.src="images/clouds.png";
document.getElementById("w_condition").innerHTML="Clouds";
}
else if (data.weather[0].main == "Snow") {
weather_i.src="images/snow.png";
document.getElementById("w_condition").innerHTML="Snow";
}
document.querySelector("#content").style.display="block";
}