JavaScript AJAX Basics (retiring) AJAX and APIs Create a callback function

Furkan Demirtürk
Furkan Demirtürk
7,938 Points

I stuck there

What can ı do

weather.js
$(document).ready(function() {
  var weatherAPI = 'http://api.openweathermap.org/data/2.5/weather';
  var data = {
    q : "Portland,OR",
    units : "metric"

  };
  function showWeather (weatherReport) {
  $("#temperature").text("weatherReport.main.temp")
  };
});
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>What's the Weather Like?</title>
  <script src="jquery.js"></script>
  <script src="weather.js"></script>
</head>
<body>
  <div id="main">
    <h1>Current temperature: <span id="temperature"></span>&deg;</h1>
  </div>
</body>
</html>

1 Answer

Andrew Hinkson
Andrew Hinkson
14,055 Points

You are very very close. I would look very closely at what your passing into .text(). As your code stands you are passing in a string it needs to be a reference to the data that you want in the api.

$('#temperature').text(weatherReport.main.temp);