-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
83 lines (74 loc) · 2.52 KB
/
Copy pathindex.js
File metadata and controls
83 lines (74 loc) · 2.52 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function GetInfo() {
var newName = document.getElementById("cityInput");
var cityName = document.getElementById("cityName");
cityName.innerHTML = newName.value;
fetch(
"https://api.openweathermap.org/data/2.5/forecast?q=" +
newName.value +
"&units=metric&appid=652400eb6610960eab93c867e918ce0d"
)
.then((response) => response.json())
.then((data) => {
//Getting the min and max values for each day
for (i = 0; i < 5; i++) {
document.getElementById("day" + (i + 1) + "Min").innerHTML =
"Temp_min: " + Number(data.list[i].main.temp_min).toFixed(1) + "°C";
//Number(1.3450001).toFixed(2); // 1.35
}
for (i = 0; i < 5; i++) {
document.getElementById("day" + (i + 1) + "Max").innerHTML =
"Temp_max: " + Number(data.list[i].main.temp_max).toFixed(2) + "°C";
}
for (i = 0; i < 5; i++) {
document.getElementById("day" + (i + 1) + "Hum").innerHTML =
"Humidity: " + Number(data.list[i].main.humidity);
}
for (i = 0; i < 5; i++) {
document.getElementById("day" + (i + 1) + "Wind").innerHTML =
"Wind Speed: " + Number(data.list[i].wind.speed);
}
for (i = 0; i < 5; i++) {
document.getElementById("day" + (i + 1) + "Date").innerHTML =
"Description: " + data.list[i].weather[0].description;
}
//Getting Weather Icons
for (i = 0; i < 5; i++) {
document.getElementById("img" + (i + 1)).src =
"http://openweathermap.org/img/wn/" +
data.list[i].weather[0].icon +
".png";
}
console.log(data);
document.body.style.backgroundImage =
"url('https://source.unsplash.com/1600x900/?'" + newName.value + ")";
})
.catch((err) =>
alert("Something Went Wrong: Try Checking Your Internet Coneciton")
);
}
function DefaultScreen() {
document.getElementById("cityInput").defaultValue = "Delhi";
GetInfo();
}
//Getting and displaying the text for the upcoming five days of the week
var d = new Date();
var weekday = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
//Function to get the correct integer for the index of the days array
function CheckDay(day) {
if (day + d.getDay() > 6) {
return day + d.getDay() - 7;
} else {
return day + d.getDay();
}
}
for (i = 0; i < 5; i++) {
document.getElementById("day" + (i + 1)).innerHTML = weekday[CheckDay(i)];
}