-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
41 lines (30 loc) · 945 Bytes
/
app.js
File metadata and controls
41 lines (30 loc) · 945 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
31
32
33
34
35
36
37
38
39
40
41
// Initialize storage
const storage = new Storage();
// Get stored location data
const weatherLocation = storage.getLocationData();
// Initialize weather object
const weather = new Weather(weatherLocation.city, weatherLocation.state);
// Initialize UI object
const ui = new UI();
// Get weather on DOM load
document.addEventListener('DOMContentLoaded', getWeather);
// Change location event
document.getElementById('w-change-btn').addEventListener('click', () => {
const city = document.getElementById('city').value;
const state = document.getElementById('state').value;
// Change location
weather.changeLocation(city, state);
// Set location in local storage
storage.setLocationData(city, state);
// Get and display weather
getWeather();
// Close modal
$('#locModal').modal('hide');
});
function getWeather() {
weather.getWeather()
.then(results => {
console.log(results);
})
.catch(err => console.log(err));
}