Hello! Welcome to the final lesson in our module on Asynchronous JavaScript.
In our last lesson, we took a deep dive into professional error handling, learning how to distinguish between network errors and HTTP status errors. You learned the crucial pattern of checking response.ok and throwing an error to centralize your error logic in a single catch block.
Today, you'll put everything from this module into practice. We're going to build a complete, functional weather dashboard. This is a classic project for aspiring web developers because it combines many essential skills:
- Manipulating the DOM to create an interactive UI.
- Handling user input from a form.
- Using
async/awaitandfetchto call a third-party API. - Applying robust error handling to provide a great user experience.
- Dynamically displaying the fetched data on the page.
By the end of this lesson, you will have built a weather dashboard that fetches and displays data from a public API based on user input, a tangible project that demonstrates your growing frontend skills.
Let's take a look at the kind of application we're aiming to build.

Step 1: Project Setup and API Key
To get real-time weather data, we need to use a service that provides it. We'll use the OpenWeatherMap API, which is free for basic use. To access it, you need a unique API key.
The first video below will guide you through the entire project. For now, let's focus on the setup.
Create a weather app with JavaScript! ☀️
This video, 'Create a weather app with JavaScript! ☀️' by Bro Code, is a complete walkthrough of the project we're building. We'll use it as our primary guide.
First, watch from the beginning until 00:53 to see how to sign up for OpenWeatherMap and get your API key. It might take 15-20 minutes for your new key to become active. Then, continue watching from 00:53 to 03:58 to build the HTML and CSS for our user interface. You can find all the necessary CSS in the video's description. The instructor creates some placeholder elements in the HTML to help with styling—we will replace these with dynamic JavaScript-generated elements later.
After this step, you should have:
- An
index.htmlfile with the form and a display card structure. - A
styles.cssfile to make it look good. - A
script.jsfile, which is currently empty. - Your personal API key from OpenWeatherMap. Save it somewhere safe; we'll need it soon.
Step 2: JavaScript - The Application Core
Now it's time to bring the application to life with JavaScript. Our script will be responsible for three main jobs:
- Listening for the user to submit a city.
- Fetching the data for that city from the OpenWeatherMap API.
- Displaying either the weather data or an error message on the screen.
Let's continue with the video to wire up our UI and prepare the functions we'll need.
Create a weather app with JavaScript! ☀️
Let's set up the main structure of our script.js file. We will select the DOM elements we need to work with, store our API key, and add the main event listener to the form.
Watch the segment from 13:49 to 17:10. This part covers: Using document.querySelector to get references to the form, input field, and display card. Storing your API key in a const variable. Adding a submit event listener to the form. Calling event.preventDefault() to stop the page from reloading. Don't worry about filling in the functions just yet; the instructor is just creating empty function shells for now.
Step 3: Fetching the Weather Data
This is where your knowledge of async/await and error handling comes into play. We will now implement the function that communicates with the OpenWeatherMap API.
Notice how the logic here directly applies the error-handling pattern from our previous lesson. We use a try...catch block to handle network failures, and inside the try block, we explicitly check response.ok to catch HTTP errors (like a 404 "City not found").
Create a weather app with JavaScript! ☀️
Let's implement the getWeatherData function. This function will construct the API URL, make the fetch call, and handle potential errors.
Watch from 20:12 to 23:54. Pay close attention to how the API URL is built using a template string and how async/await is used to manage the fetch call. Most importantly, see how if (!response.ok) is used to throw an error, which is exactly the pattern we discussed in the last lesson.
At this point, you have the logic to fetch and parse the weather data. The next step is to display it.
Step 4: Displaying Data and Handling Errors
Once we have the weather data as a JSON object, we need to extract the relevant information and dynamically create HTML elements to show it to the user. We'll also implement the displayError function that we call from our catch block.
This is a great exercise in DOM manipulation. Instead of having static elements in our HTML, we'll create, configure, and append them using JavaScript. This makes our application flexible and robust.
Create a weather app with JavaScript! ☀️
Now we'll build the functions to display the weather data, a corresponding emoji, and any error messages.
This is the final implementation part. Please watch the following segments: Displaying Weather Info (23:54 - 33:16): This is a detailed section. Notice the use of object destructuring to extract data, document.createElement to build the UI dynamically, and .appendChild to add the elements to the card. Getting the Weather Emoji (33:16 - 38:03): This part shows how to use a switch statement based on the weather ID from the API to display a relevant emoji. It's a nice touch that makes the UI more engaging. Displaying Errors (17:10 - 20:12): This part implements the displayError function. It dynamically creates a paragraph element, sets its content to the error message, and displays it in the card.
After completing this step, your weather dashboard should be fully functional! Try searching for a city, searching for a nonsense name to see the error, and clicking "Get Weather" with no input.
Test your understanding!
The video implemented the logic to convert the temperature from Kelvin to Fahrenheit. Let's modify your displayWeatherData function to show the temperature in Celsius instead.
- Find the line where the temperature's
textContentis set. - The API provides the temperature in Kelvin. The formula to convert Kelvin to Celsius is:
Celsius = Kelvin - 273.15. - Use the
.toFixed(1)method to round the result to one decimal place. - Update the text to display the
°Csymbol.
Show answer
In your displayWeatherData function, you should find the section for tempDisplay. Modify it to look like this:
// ...inside displayWeatherData function
const tempInCelsius = (temp - 273.15).toFixed(1);
tempDisplay.textContent = `${tempInCelsius}°C`;
// The rest of the code for adding classList and appending remains the same
tempDisplay.classList.add("tempDisplay");
card.appendChild(tempDisplay);
// ...
Conclusion
Congratulations! You have successfully built a complete, data-driven web application from scratch. You've integrated user input, asynchronous API calls, dynamic DOM manipulation, and robust error handling—all fundamental skills for a modern web developer.
Key Takeaways:
- You built a practical application by combining HTML, CSS, and JavaScript.
- You used
fetchwithasync/awaitto consume data from a real-world, third-party API. - You applied the graceful error handling pattern (
try...catchwith a!response.okcheck) to create a reliable user experience. - You practiced dynamic DOM manipulation by creating and appending elements based on API data.
This project marks the end of our deep dive into asynchronous JavaScript. You've learned the theory and immediately applied it to a tangible project.
In the next module, we will begin our journey into React. You've now seen how much work it can be to manipulate the DOM directly (createElement, appendChild, textContent, etc.). You'll soon discover how libraries like React provide a much more powerful, efficient, and structured way to build complex and interactive user interfaces.