-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
94 lines (85 loc) · 2.23 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
$(document).ready(function() {
navigator.geolocation.getCurrentPosition(success, error);
function success(pos) {
var lat = pos.coords.latitude;
var long = pos.coords.longitude;
weather(lat, long);
}
function error() {
console.log("There was an error");
}
function weather(lat, long) {
var URL = `https://fcc-weather-api.glitch.me/api/current?lat=${lat}&lon=${long}`;
$.getJSON(URL, function(data) {
display(data);
});
}
function display(data) {
var city = data.name.toUpperCase();
var temp =
Math.round(data.main.temp_max) +
"° C | " +
Math.round(Math.round(data.main.temp_max) * 1.8 + 32) +
"° F";
var desc = data.weather[0].description;
var date = new Date();
var months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
];
var weekday = new Array(7);
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
var font_color;
var bg_color;
if (Math.round(data.main.temp_max) > 25) {
font_color = "#ffffff";
bg_color = "#000000";
} else {
font_color = "#ffffff";
bg_color = "#000000";
}
if (data.weather[0].main == "Sunny" || data.weather[0].main == "sunny") {
$(".weathercon").html(
"<i class='fas fa-sun' style='color: #d36326;'></i>"
);
} else {
$(".weathercon").html(
"<i class='fas fa-cloud' style='color: #44c3de;'></i>"
);
}
var minutes =
date.getMinutes() < 11 ? "0" + date.getMinutes() : date.getMinutes();
var date =
weekday[date.getDay()].toUpperCase() +
" | " +
months[date.getMonth()].toUpperCase().substring(0, 3) +
" " +
date.getDate() +
" | " +
date.getHours() +
":" +
minutes;
$(".location").html(city);
$(".temp").html(temp);
$(".date").html(date);
$(".box").css("background", bg_color);
$(".location").css("color", font_color);
$(".temp").css("color", font_color);
}
});