-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (23 loc) · 709 Bytes
/
app.js
File metadata and controls
30 lines (23 loc) · 709 Bytes
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
// Init storage class
const storage = new Storage;
const loc = storage.getLocationData();
//Init weather class
const weather = new Weather(loc);
//Init Ui class
const ui = new Ui;
// on load
document.addEventListener('DOMContentLoaded',getWeather())
//change city
document.getElementById('save-changes').addEventListener('click',(e)=>{
const city = document.getElementById('city-new').value;
city === '' ? alert('Field cannot be empty') : weather.updateCity(city);
getWeather();
storage.setLocationData(city);
})
function getWeather() {
weather.getWeather()
.then(res => {
ui.showData(res);
})
.catch(err => alert('something went wrong!'));
}