OpenWeatherMap API: Uncaught TypeError - Cannot read property 'temp' of undefined(...)
<p>Newbie here, I am trying to access temperature from the OpenWeatherMap API for a project from FreeCodeCamp. But my problem is that whenever I attempt to access the temperature value using the nested JSON object, the console suggests the parent of &quot;temp&quot; is undefined. Why is it undefined?</p>
<p>This is the code that is giving me problems:</p>
<pre class="lang-js prettyprint-override"><code>$.getJSON(url, function(data) {
    console.log(&quot;successful request&quot;);
    console.log(data.main.temp);
    console.log(&quot;successful temperature access&quot;);
  });
</code></pre>
<p>When I run this, the console logs &quot;successful request,&quot; then gives me the error:</p>
<blockquote>
<p>Uncaught TypeError - Cannot read property 'temp' of undefined(...).</p>
</blockquote>
<p>Things I have tried: I looked at sample code and referred to the API documentation, and saw <code>data.main.temp</code> was a valid method of accessing temperature. I verified that the <code>data</code> object was parsed and made sure that it was not contained in an array. Also, I have verified the url. Here is a beginning snippet of what the URL leads to:
<a href="https://i.stack.imgur.com/NlQvK.png" rel="nofollow noreferrer">link.</a></p>
<p>Working off Chrome. <a href="http://codepen.io/collindching/pen/jVjXWL?editors=0011" rel="nofollow noreferrer">Link</a> to Codepen project.</p>