-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
53 lines (43 loc) · 1.64 KB
/
script.js
File metadata and controls
53 lines (43 loc) · 1.64 KB
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 temp1=document.getElementById("temp1")
const temp2=document.getElementById("temp2")
const p1=document.getElementById("got1")
const p2=document.getElementById("got2")
const feels_like=document.getElementById("feels_like")
const humidity=document.getElementById("humidity")
const pressure=document.getElementById("pressure")
const visiblity=document.getElementById("visiblity")
const discription=document.getElementById("discription")
const wind_speed=document.getElementById("wind_speed")
const image=document.getElementById("img")
option={
methord:'GET'
}
function getwether(city){
temp1.innerText=city
let iconcode
fetch(`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=8309b8f0f5e135597d20d8d61fd02045`,option)
.then(response=>response.json())
.then((response)=>{
console.log(response)
let g=Math.round((response.main.feels_like - 273)*100)/100
let tempo=Math.round((response.main.temp -273)*100)/100
temp2.innerText= tempo
feels_like.innerText= ` Feels Like : `+g +` °C`
humidity.innerText= ` Humidity : `+response.main.humidity + ` %`
pressure.innerText=` Pressure : `+response.main.pressure + ` hpa`
visiblity.innerText=` Visiblity : `+response.visibility + ` M`
discription.innerText=` Discription : `+response.weather[0].description
wind_speed.innerText=` Wind Speed : `+response.wind.speed+` meter/sec`
iconcode=response.weather[0].icon
image.src="http://openweathermap.org/img/w/" + iconcode + ".png";
})
.catch((err)=>{
console.log(err)
})
}
got2.onclick=(e)=>{
console.log(got1.value)
e.preventDefault()
getwether(got1.value)
}
getwether("delhi");