-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (26 loc) · 1.14 KB
/
Copy pathscript.js
File metadata and controls
38 lines (26 loc) · 1.14 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
const inputvalue = document.querySelector('#c_input')
const btn = document.querySelector('#add')
const city = document.querySelector('#c_output')
const descrip = document.querySelector('#desc')
const temp = document.querySelector('#temp')
const wind = document.querySelector('#wind')
api="8649f515f8cd97fabd726bc80549ee25"
function covertion(val){
return (val-273).toFixed(2)
}
btn.addEventListener('click', function(){
fetch('https://api.openweathermap.org/data/2.5/weather?q='+inputvalue.value+'&appid='+api)
.then(res => res.json())
.then(data =>
{
const nameval = data['name']
const descrip = data['weather']['0']['description']
const tempa = data['main']['temp']
const windspeed = data['wind']['speed']
city.innerHTML=`weather of <span>${nameval}<span>`
descrip.innerHTML = `Sky conditions: <div>${descrip}<div>`
temp.innerHTML= `Temperature: <span>${covertion(tempa)}C<span>`
wind.innerHTML = `Wind speed: <span>${windspeed}km/h<span> `
})
.catch(err=> alert('You entered wrong information'))
})