-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
27 lines (21 loc) · 1.02 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
const url = 'https://api.openweathermap.org/data/2.5/'
const apiKey = 'OPENWEATHERMAP_API_KEY';
let searchİnput = document.getElementById('search');
let city = document.getElementsByClassName('city');
let temp = document.getElementsByClassName('temp');
let desc = document.getElementsByClassName('desc');
let minmax = document.getElementsByClassName('minmax');
let searchBtn = document.getElementById('searchBtn');
searchBtn.addEventListener('click', getWheather);
function getWheather() {
fetch(`${url}weather?q=${searchİnput.value}&units=metric&appid=${apiKey}`)
.then(response => response.json())
.then(data => {
//console.log(data); // index??
city[0].innerHTML = data.name;
temp[0].innerHTML = Math.round(data.main.temp) + ' °C';
desc[0].innerHTML = data.weather[0].description;
minmax[0].innerHTML = Math.round(data.main.temp_min) + ' ℃' + ' / ' + Math.round(data.main.temp_max) + ' ℃';
})
.catch(err => alert('Wrong City Name!'))
}