-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
23 lines (20 loc) · 863 Bytes
/
app.js
File metadata and controls
23 lines (20 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const API_KEY = `46ad7457603b9b0104e633e78cd60e16`;
const searchTemperature = () => {
const city = document.getElementById('city-name').value;
const url = `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${API_KEY}&units=metric`;
fetch(url)
.then(res => res.json())
.then(data => displayTemperature(data));
}
const setInnerText = (id, text) => {
document.getElementById(id).innerText = text;
}
const displayTemperature = temperature => {
setInnerText('city', temperature.name);
setInnerText('temperature', temperature.main.temp);
setInnerText('condition', temperature.weather[0].main);
// set weather icon
const url = `http://openweathermap.org/img/wn/${temperature.weather[0].icon}@2x.png`;
const imgIcon = document.getElementById('weather-icon');
imgIcon.setAttribute('src', url);
}