-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
64 lines (53 loc) · 1.49 KB
/
script.js
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
const button = document.querySelector(".weather__input-button");
const input = document.querySelector(".weather__input-searchBox");
const city = document.querySelector(".weather__details-city");
const date = document.querySelector(".weather__details-date");
const temp = document.querySelector(".weather__details-temp");
const description = document.querySelector(".weather__details-description");
button.addEventListener("click", function () {
fetch(
`https://api.openweathermap.org/data/2.5/weather?q=${input.value}&appid=8241dd5ea92d0d5d64368af5ceb5187f&units=metric`
)
.then((response) => response.json())
.then(displayData);
});
const displayData = (weather) => {
city.innerHTML = `${weather.name}, ${weather.sys.country}`;
console.log(city);
temp.innerHTML = `${Math.round(weather.main.temp)}°C`;
console.log(temp);
description.innerHTML = `${weather.weather[0].description}`;
console.log(description);
let now = new Date();
date.innerHTML = dateBuilder(now);
};
function dateBuilder(d) {
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[d.getDay()];
let date = d.getDate();
let month = months[d.getMonth()];
let year = d.getFullYear();
return `${day} ${date} ${month}, ${year}`;
}