Help in Local Weather Challenge

hey i was hoping someone could explain to me why my temp variable is coming out as undefined does it have to do something with scope? Sorry i am very new to this. Thank you.

Its because of $.getJSON being asynchronous. When you’re printing temp to console it is not set yet, no data yet received from the server.

Add this code to the end of your code and see for yourself:

console.log("temp at the beginning", temp);
(function() {
  setTimeout(function() {
    console.log("temp after 1s timeout", temp);
  }, 1000)
})();

This will print in console temp at the start and then again after 1 second.

Read jQuery.getJSON() in jQuery’s documentation/

Thank you that was really helpful!!