-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
43 lines (31 loc) · 1.07 KB
/
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const url = 'https://api.openweathermap.org/data/2.5/';
const key = 'aee9368ab4b3e538bec75d39005eccf3';
const setQuery = (e) => {
if (e.keyCode=='13'){
getResault(searchBar.value);
}
};
const getResault = (cityName) =>{
if (cityName==""){
alert("Şehir adı boş bırakılamaz")
}
let query = `${url}weather?q=${cityName}&appid=${key}&units=metric&lang=tr`;
fetch(query)
.then(weather => {
return weather.json();
})
.then(displayResult);
};
const displayResult= (result) =>{
let city = document.querySelector('.city');
city.innerText = `${result.name}${result.sys.country}`;
let temp = document.querySelector('.temp');
temp.innerText = `${Math.round(result.main.temp)}°C `;
let desc = document.querySelector('.desc');
desc.innerText = result.weather[0].description;
let minmax= document.querySelector('.minmax');
minmax.innerText = `Min :${Math.round(result.main.temp_min)}°C
Maks: ${Math.round(result.main.temp_max)}°C`;
};
const searchBar = document.querySelector('#searchBar');
searchBar.addEventListener('keypress' , setQuery);