Format JS

This commit is contained in:
Tressley Cahill 2022-11-01 17:12:52 -04:00
parent 723d73e127
commit ec99ce4b15
2 changed files with 22 additions and 19 deletions

View File

@ -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,

View File

@ -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 + '&deg;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 + '&deg;F">' + data.weather[0].description + '<span class="separator">|</span>' + tempC + '&deg;C</p>';
});
} }
function traichu() { function traichu() {
dateTime(); dateTime();
weatherBalloon(6254926); weatherBalloon(6254926);
} }