async function fetchWeatherData(location, startDate, endDate, apiKey) {
const baseUrl =
"https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline";
const url = `${baseUrl}/${encodeURIComponent(
location
)}/${startDate}/${endDate}?unitGroup=us&include=days&key=${apiKey}&contentType=json`;
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const weatherData = await response.json();
console.log(weatherData);
return weatherData;
} catch (error) {
console.error("Error fetching weather data:", error);
}
}