Help Weather Project (javascript)

Hello campers,

I have been having some problems regarding fetch() in javascript. I have been trying to use it to get the JSON of the API. Even though the code was supposed to work, I have not been able to use the fetch response outside the function as it is assigned to a local variable, therefore I cannot acess the json. Would be really glad if someone could help me. Thanks.

Hey. Seems like you are passing an undefined paramater to .getCurrentPosition(). Shouldn’t that be .getCurrentPosition(apiLink)?

Aside from that, the getCurrentPosition method is asynchronous. You may set a variable, but javascript will execute the function that needs that variable (api) before it gets updated.

So, call your json() function inside the apiLink() one, passing it the api variable: json(api). After that, you can remove the click event you have at the end of your code (because you are already calling the json function anyway).