"Weather not defined"

I’m somewhat new to working with API’s using vanilla JavaScript and I keep running into this error when trying to fetch the weather data . The console keeps reading “weather is not defined”. I’m using the open weather map API. In theory I should be able to retrieve using function. but that doesn’t work, along with the other variations I’ve tried. Here is my current code:

 let weather={"apiKey": "DATA EXPUNGED",

.then((response) => response.json())

I have posted the link in fetch.It just wasn’t getting uploaded here.


This text will be hidden

Can you post your code again between backticks like this:


First please don’t publicly post your API keys.

Here’s the format for an API call for the weather API.

fetch(`https://history.openweathermap.org/data/2.5/aggregated/day?lat={lat}&lon={lon}&month={number of the month}&day={number of the day}&appid={API key}`)

You always need to pass in the URL to the place you’re trying to reach inside the fetch call along with any parameters you need.

Hope this helps. :slight_smile:

1 Like

Thank you for your response.
I have tried to pass in the URL inside the fetch call but my console is still showing that my weather is not defined :frowning:

This can occur when you attempt to access it when it’s not defined in the same scope.

1 Like

Can you show me the fetch statement?