A responsive and interactive weather application that provides real-time updates using the OpenWeatherMap API. This project demonstrates advanced Vanilla JavaScript techniques, specifically focusing on asynchronous data fetching and dynamic UI rendering.
As a developer, I focused on making this app robust by implementing a structured "Fetch-and-Display" cycle:
Unlike static apps, this project communicates with a remote server.
- The Logic: I used
async/awaitto handle thefetchrequest to the OpenWeatherMap API. - Why? This ensures the application remains responsive and doesn't "freeze" while waiting for the weather data to travel across the internet.
Instead of just showing text, the app uses a switch(true) statement to analyze the weatherId returned by the API.
- The Process: It maps specific ID ranges (e.g., 200s for Thunderstorms, 800 for Clear Skies) to unique emojis.
- Detail: I used Unicode sequences (like
\uFE0F) to ensure consistent emoji rendering across different operating systems.
A key part of software engineering is preparing for things to go wrong.
- Input Validation: The app checks if the input is empty before making a request to save API bandwidth.
- Try...Catch Blocks: If a user enters a non-existent city or the network fails, the
catchblock intercepts the error and triggers a user-friendly error message on the card.
- HTML5: Semantic structure for forms and weather data containers.
- CSS3: Features a modern
linear-gradientbackground that adds depth to the weather card. - JavaScript (ES6+): Utilizes
const/let, arrow functions, template literals, and destructuring for clean, readable code. - OpenWeatherMap API: The external data source for global weather information.
- Real-time Conversion: Data is fetched in Kelvin and mathematically converted to Celsius using
(temp - 273.15).toFixed(1). - Dynamic DOM Injection: Elements like
h1andpare created and appended in real-time based on the search result. - Responsive Design: Styled with Flexbox to ensure the weather card remains centered and readable on all screen sizes.
Through this project, I deepened my understanding of the Request-Response cycle, learned how to securely use API Keys, and practiced Object Destructuring to extract specific data points from large JSON objects.