-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
51 lines (38 loc) · 1.27 KB
/
app.js
File metadata and controls
51 lines (38 loc) · 1.27 KB
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
46
47
48
49
50
51
//Init Storage
const storage = new Storage();
//Get Stored Location data
const weatherLocation = storage.getLocationData();
console.log(weatherLocation.city + " " + weatherLocation.country);
//Init Weather Object
const weather = new Weather(weatherLocation.city, weatherLocation.country);
//Init UI
const ui = new UI();
// weather.changeLocation("Delhi", "IN");
//Get Weather on DOM Load
document.addEventListener("DOMContentLoaded", getWeather);
//Change Location Event
document.getElementById("w-change-btn").addEventListener("click", (e) => {
const city = document.getElementById("city").value;
const country = document.getElementById("country").value;
weather.changeLocation(city, country);
//Set Location in LS
storage.setLocationData(city, country);
//Get and display weather
getWeather();
//Close Modal
$("#locModal").modal("hide");
});
function getWeather() {
weather
.getWeather()
.then((result) => ui.paint(result))
.catch((err) => console.log(err));
}
// document.getElementById("w-change-btn").addEventListener("click", () => {
// const cityname = document.getElementById("city").value;
// console.log(cityname);
// weather
// .getWeather()
// .then((results) => console.log(results))
// .catch((err) => console.log(err));
// });