-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
26 lines (21 loc) · 887 Bytes
/
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
var input = document.querySelector('.input_text');
var main = document.querySelector('#name');
var temp = document.querySelector('.temp');
var desc = document.querySelector('.desc');
var clouds = document.querySelector('.clouds');
var button= document.querySelector('.submit');
button.addEventListener('click', function(name){
fetch('https://api.openweathermap.org/data/2.5/weather?q='+input.value+'&appid=d78785a6d83ea106897727876d2b3645')
.then(response => response.json())
.then(data => {
var tempValue = data['main']['temp'];
tempValue = (tempValue - 273.15).toFixed(1);
var nameValue = data['name'];
var descValue = data['weather'][0]['description'];
main.innerHTML = nameValue;
desc.innerHTML = "Description - "+descValue;
temp.innerHTML = "Temp - "+tempValue+ '°C;';
input.value ="";
})
.catch(err => alert("Wrong city name!"));
})