Position of console.log test matters- no idea why!

Position of console.log test matters- no idea why!
0.0 0

#1

I am doing baby step tests whilst defining vars. I have 2 outputs to console log. The one above the var list fires fine, the one below the var list does not even fire. (If I comment our the var list then the second fires and returns the expected “undefined”).

Can someone explain this behaviour, so unexpected by me.

Pen is here: https://codepen.io/m4sterbunny/pen/GdbvMW

console.log("first push " + data.list[0]["name"]);
      
   
  var tempK = Math.round(data.main.temp);
  var tempC = tempK - 273;
  var tempF = tempK*(9/5)-459.67;
  var wind = data.wind.speed;
  var location = data.list[0]["name"];
  
  console.log("second push " + location); 

console.log("first push " + data.list[0][“name”]); // returns Claremont
console.log("second push " + location); // no return


#2

You need:

  var tempK = Math.round(data.list[0].main.temp);
  var tempC = tempK - 273;
  var tempF = tempK*(9/5)-459.67;
  var wind = data.list[0].wind.speed;
  var location = data.list[0].name;

in order to work.
If you console.log(data) right after $.getJSON(url, function(data){ and take a look into browser 's devtools you will see that list is an array length 1 that means you can access the objects in the array by using data.list[0].name_of_key


#3

thanks @sorinr, duh the vars were breaking it.

Great tip about the devtools- I am only working in console and the JS window in codepen. I will go take a peek.


#4

@sorinr Dude you are a life saver. I can see my data- its structure and drill down in a logical manner. FCC guys you need to guide us to here before setting us off on projects!