Format JS
This commit is contained in:
parent
723d73e127
commit
ec99ce4b15
@ -27,7 +27,6 @@ header {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#date,
|
#date,
|
||||||
#location {
|
#location {
|
||||||
color: var(--primary-link-hover-color);
|
color: var(--primary-link-hover-color);
|
||||||
@ -40,6 +39,8 @@ header {
|
|||||||
text-transform: capitalize;
|
text-transform: capitalize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#weather { text-align: right; }
|
||||||
|
|
||||||
.separator { margin: 0 0.25rem; }
|
.separator { margin: 0 0.25rem; }
|
||||||
|
|
||||||
header img,
|
header img,
|
||||||
|
|||||||
36
js/main.js
36
js/main.js
@ -1,24 +1,26 @@
|
|||||||
function dateTime () {
|
function dateTime() {
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
let today = date.toDateString();
|
let today = date.toDateString();
|
||||||
let time = date.toLocaleTimeString();
|
let time = date.toLocaleTimeString();
|
||||||
document.getElementById('date-time').innerHTML = '<p id="date">' + today + '</p><p id="time">' + time + '</p>';
|
document.getElementById('date-time').innerHTML = '<p id="date">' + today + '</p><p id="time">' + time + '</p>';
|
||||||
setTimeout(dateTime, 1000);
|
setTimeout(dateTime, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function weatherBalloon(cityID) {
|
function weatherBalloon(cityID) {
|
||||||
var apiKey = 'fad9628260a1bc2ebaaf85a7dfe800d0';
|
var apiKey = 'fad9628260a1bc2ebaaf85a7dfe800d0';
|
||||||
fetch('https://api.openweathermap.org/data/2.5/weather?id=' + cityID + '&appid=' + apiKey)
|
fetch('https://api.openweathermap.org/data/2.5/weather?id=' + cityID + '&appid=' + apiKey)
|
||||||
.then(function(resp) { return resp.json() })
|
.then(function(resp) {
|
||||||
.then(function(data) {
|
return resp.json()
|
||||||
let tempK = parseFloat(data.main.temp);
|
})
|
||||||
let tempC = Math.round(tempK-273.15);
|
.then(function(data) {
|
||||||
let tempF = Math.round((tempK-273.15)*1.8)+32;
|
let tempK = parseFloat(data.main.temp);
|
||||||
document.getElementById('weather').innerHTML = '<p id="location">' + data.name + '</p><p id="details">' + data.weather[0].description + '<span class="separator">|</span>' + tempC + '°C</p>';
|
let tempC = Math.round(tempK - 273.15);
|
||||||
});
|
let tempF = Math.round((tempK - 273.15) * 1.8) + 32;
|
||||||
|
document.getElementById('weather').innerHTML = '<p id="location">' + data.name + '</p><p id="details" ' + 'title="' + tempF + '°F">' + data.weather[0].description + '<span class="separator">|</span>' + tempC + '°C</p>';
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function traichu() {
|
function traichu() {
|
||||||
dateTime();
|
dateTime();
|
||||||
weatherBalloon(6254926);
|
weatherBalloon(6254926);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user