startpage/js/main.js
2022-11-02 09:36:20 -04:00

28 lines
1.1 KiB
JavaScript

function dateTime() {
const date = new Date();
let today = date.toDateString();
let time = date.toLocaleTimeString();
document.getElementById('date-time').innerHTML = '<p id="date">' + today + '</p><p id="time">' + time + '</p>';
setTimeout(dateTime, 1000);
}
function weatherBalloon(cityID) {
var apiKey = 'fad9628260a1bc2ebaaf85a7dfe800d0';
fetch('https://api.openweathermap.org/data/2.5/weather?id=' + cityID + '&appid=' + apiKey)
.then(function(resp) {
return resp.json()
})
.then(function(data) {
let weatherIcon = data.weather[0].icon;
let tempK = parseFloat(data.main.temp);
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">' + '<img src="http://openweathermap.org/img/wn/' + weatherIcon + '@2x.png">' + data.weather[0].description + '<span class="separator">|</span>' + tempC + '&deg;C</p>';
});
}
function traichu() {
dateTime();
weatherBalloon(6254926);
}