-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser-interface.js
More file actions
66 lines (59 loc) · 1.91 KB
/
user-interface.js
File metadata and controls
66 lines (59 loc) · 1.91 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Define class User Interface
class UI {
constructor() {
this.location = document.getElementById("location");
this.date = document.getElementById("date");
this.temp = document.getElementById("temp");
this.icon = document.getElementById("icon");
this.details = document.getElementById("details");
this.hiLow = document.getElementById("hi-low");
this.humidity = document.getElementById("humidity");
this.wind = document.getElementById("wind");
}
// Show data from weather API
showData(weather) {
// Set data from weather API
this.location.textContent = weather.name;
// Get current date
function dateBuilder(currentDate) {
let months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
let days = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
let day = days[currentDate.getDay()];
let date = currentDate.getDate();
let month = months[currentDate.getMonth()];
let year = currentDate.getFullYear();
return `${day} ${date} ${month} ${year}`;
}
this.date.innerText = dateBuilder(now);
this.icon.setAttribute(
"src",
"http://openweathermap.org/img/wn/" + weather.weather[0].icon + "@2x.png"
);
this.temp.textContent = `Current: ` + weather.main.temp + `°c`;
this.details.textContent = `Description: ${weather.weather[0].main} / ${weather.weather[0].description}`;
this.hiLow.textContent = `Max - Min : ${weather.main.temp_max} °c / ${weather.main.temp_min} °c`;
this.humidity.textContent = `Relative Humidity: ${weather.main.humidity} %`;
this.wind.textContent = `Wind: ${weather.wind.deg}° / ${weather.wind.speed} m/s`;
}
}