. Hello y\'all, I\'m trying to implement this tutorial as a module in a page but I am getting a \"weatherData.temperature is null\" error.
I had previously been getting
You likely need to check the readyState
in your onreadystatechange
.
document.onreadystatechange = function () {
if (document.readyState === "interactive") {
// ...
getLocationAndWeather();
}
};
Sample: document.readyState
Also you need to change
<a href="temperature"
to
<a id="temperature"
To get switchUnits
running, you'll need
switchUnits = function switchUnits () {
if (weatherData.units == "°C"){
weatherData.temperatureValue = weatherData.temperatureValue * 9/5 + 32;
weatherData.units = "°F";
} else {
weatherData.temperatureValue = (weatherData.temperatureValue - 32) * 5/9;
weatherData.units = "°C";
}
weatherData.temperature.innerHTML = weatherData.temperatureValue + weatherData.units + ", ";
};
... so the function is published to the window
.