function getUserLocation() {
return new Promise((resolve) => {
setTimeout(() => {
resolve({ lat: 40.7128, lon: -74.0060 }); // New York City
}, 1000); // Simulating a delay
});
}
function getWeatherData(location) {
return new Promise((resolve) => {
setTimeout(() => {
resolve({ temp: 72, condition: "Sunny" });
}, 1500); // Simulating a delay
});
}
function displayWeather(weather) {
console.log(`The weather is ${weather.temp}°F and ${weather.condition}`);
}
// Using our asynchronous functions
getUserLocation()
.then(location => getWeatherData(location))
.then(weather => displayWeather(weather))
.catch(error => console.error("An error occurred:", error));
console.log("Weather app initialized!");