I have the following functions for getting data from an API and setting the text of an HTML element by its ID:
var api_url = "https://api.wheretheiss.at/v1/satellites/25544";
var coordinates = {
latitude : 0,
longitude : 0
}
async function getISS() {
const response = await fetch(api_url);
const data = await response.json();
const {latitude, longitude} = data;
var spaceStationCoordinates = new coordinates({
latitude: latitude,
longitude: longitude
});
return spaceStationCoordinates;
}
async function setText(id,newvalue) {
var s= document.getElementById(id);
s.innerHTML = newvalue;
}
And then I use the functions to try and insert the latitude and longitude values in my HTML:
<main>
<h1>Where is the ISS?</h1>
<p>Latitude: <span id="lat" type = text>""</span></p> <br>
<p>Longitude: <span id="lon" type = text>""</span></p>
<script src="js/script.js" type="text/javascript">
var longitude = 0;
var latitude = 0;
latitude = getISS().latitude;
longitude = getISS().longitude;
setText(lat, latitude);
setText(lon, longitude);
</script>
</main>
However this doesn't do anything at all. Any help is appreciated.