-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
61 lines (51 loc) · 1.94 KB
/
main.js
File metadata and controls
61 lines (51 loc) · 1.94 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
function getWeather() {
var cityName = document.querySelector(".inputText").value;
var dateName = document.querySelector(".inputDate").value;
fetch(
"https://meta-weather.vercel.app/api/location/search/?query=" + cityName
)
.then(function weather(data) {
return data.json();
})
.then(function weather(data) {
var woeId = data[0].woeid;
fetch(
"https://meta-weather.vercel.app/api/location/" +
woeId +
"/" +
dateName +
"/"
)
.then(function weather(data) {
return data.json();
})
.then(function weather(data) {
console.log(data);
var weatherData = data[0];
var date = getDate(weatherData.created);
var generalWeather = weatherData.weather_state_name;
var temp = weatherData.the_temp;
var humidity = weatherData.humidity;
var wind = weatherData.wind_speed;
console.log(date, generalWeather, temp);
var cityElement = document.querySelector(".city-name");
cityElement.textContent = cityName;
var subtitleTextElement = document.querySelector(".subtitle");
subtitleTextElement.textContent = date + ", " + generalWeather;
var tempElement = document.querySelector(".temperature");
tempElement.textContent = parseInt(temp) + "° C";
var humidityEl = document.querySelector("#humidity");
humidityEl.textContent = "Humidity: " + humidity + "%";
var windEl = document.querySelector("#wind");
windEl.textContent = "Wind " + parseInt(wind) + "km/h";
});
});
}
function getDate(dateString) {
var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
var d = new Date(dateString);
return `${days[d.getDay()]}, ${d.toLocaleTimeString("en-US", {
hour: "numeric",
minute: "numeric",
})}`;
}