I am working on a project where I pull an API of US GDP and then create a graph from the data. Right now I'm hung up on the first part of the problem in that I am struggling to get the JSON to store in a variable so I can work with it in the rest of my project. I've looked at a few other threads and haven't gotten a solution to work for me.
Below is my current code.
let jsondata =;
fetch('https://raw.githubusercontent.com/FreeCodeCamp/ProjectReferenceData/master/GDP-data.json').then(
function(u){ return u.json();}
).then(
function(json){
jsondata = json;
console.log(jsondata)
}
)
console.log(jsondata)
Currently, I can console.log(json) and console.log(jsondata) within my second function. However, even though I've declared the variable outside of the function, it doesn't make the variable its self global. What am I missing?