I'm currently having some trouble getting spans to work with this function I made in Javascript. It calls the OpenWeatherMap API and outputs current weather conditions, but adding CSS to the mix doesn't effect the spans I need it to, although doing the same sort of thing in a function to update the time does it perfectly well.
EDIT: Should probably mention that the digitalFont
in my CSS is a custom font, and works perfectly fine with my other CSS elements.
JS:
function getCurrentWeather() {
fetch('https://api.openweathermap.org/data/2.5/weather?q=Tokyo&appid=')
.then(res => res.json())
.then(res => {
var icon = res.weather.map(d => {return d.icon});
var con = res.weather.map(d => {return d.main});
var tempC = Math.floor(res.main.temp - 273.15);
// var tempF = Math.floor((res.main.temp - 273.15) * 1.8 + 32);
var iconPNG = `../res/img/weather_icons/${icon}.png`
document.getElementById('tempC').innerHTML = `${tempC}`;
// // document.getElementById('tempF').innerHTML = `${tempF}`;
document.getElementById('condition').innerHTML = `${con}`
document.getElementById('icon').innerHTML = `<img src="${iconPNG}">`
});
}
getCurrentWeather();
setInterval(getCurrentWeather, 3600000) // Update every hour
HTML:
<div class="weather">
<span id="tempC"></span>C
<span id="condition"></span>
<span id="icon"></span>
</div>
<script src="index.js"></script>
CSS:
.tempC {
font-family: digitalFont;
font-size: 60px;
text-align: right;
}