-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
45 lines (35 loc) · 958 Bytes
/
main.js
File metadata and controls
45 lines (35 loc) · 958 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
42
43
44
45
// Init storage object
const storage = new Storage();
// Get stored location data
const weatherLocation = storage.getLocationData();
// Init weather object
const weather = new Weather(weatherLocation.city);
// Init date object
let now = new Date();
// Init UI object
const ui = new UI();
// Get weather on DOM load
document.addEventListener("DOMContentLoaded", getWeather);
// Change location event
// Get input value
const city = document.getElementById("city");
city.addEventListener("keyup", function (e) {
if (e.key === "Enter") {
// Change location
weather.changeLocation(city.value);
let storedCity = city.value;
// Set location in local storage
storage.setLocationData(storedCity);
// Get and display weather
getWeather();
}
});
// Define get weather data
function getWeather() {
weather
.getWeather()
.then((results) => {
ui.showData(results);
})
.catch((err) => console.log(err));
}