-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
31 lines (25 loc) · 1.11 KB
/
script.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
var placesAutocomplete = places({
apiKey: "AIzaSyAxjM0mqHXT1jeFLNtsbe7GJAnMoAD-gmg",
container: document.querySelector('#city')
});
const apiKey = 'b6cc4392568a3586e950307c86a22bbd';
const apiBase = 'https://api.openweathermap.org/data/2.5/weather';
const getWeatherData = city => {
const url = `${apiBase}?q=${city}&units=metric&appid=${apiKey}`;
fetch(url)
.then(response => response.json())
.then(data => updateUI(data))
}
const searchBtn = document.getElementById('search_button');
searchBtn.addEventListener('click', () => {
const inputCity = document.getElementById('city').value;
getWeatherData(inputCity)
})
const updateUI = data => {
document.getElementById('show_city').innerText = data.name || "Unknown Location!";
document.getElementById('show_temperature').innerText = data.main.temp;
document.getElementById('weather_status').innerText = data.weather[0].main;
document.getElementById('icon').setAttribute('src', `https://openweathermap.org/img/wn/${data.weather[0].icon}@2x.png`);
document.getElementById('city').value = "";
}
getWeatherData('Chittagong');