-1

I need to identify and fix the error. What am I missing here and why? The temperature does not display.

<script type="text/javascript">
  $.ajax({
    url: 'https://api.weather.gov/gridpoints/EWX/155,90/forecast/hourly'
  }).done(function(res) {
    var temp = res.properties.periods[0].temperature;
  });
  document.getelementbyid('temperature').innerHTML = temp
</script>
<p>
  The temperature is <span id="temperature"></span>F.
</p>
Hassan Imam
  • 21,956
  • 5
  • 41
  • 51
lunik
  • 3
  • 2

1 Answers1

0

The issue here is two-fold. The first is that there is a scoping issue trying to bring "temp" outside of when it will be ready. That is only set within the .done() call.

The second issue found is that the document.getelementbyid should be document.getElementById() as per the specification https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById

<script type="text/javascript">
$(function() {
  $.ajax({
    url: 'https://api.weather.gov/gridpoints/EWX/155,90/forecast/hourly'
  }).done(function(res) {
      document.getElementById('temperature').innerHTML = res.properties.periods[0].temperature;
  });
});
</script>
<p>
    The temperature is <span id="temperature"></span>F.
</p>
hppycoder
  • 1,016
  • 1
  • 6
  • 13