This is a simple weather application built using HTML, CSS, and JavaScript. It utilizes the OpenWeatherMap API to fetch current weather data for a given location and dynamically updates the page using DOM manipulation.
- Introduction
- Features
- Technologies Used
- Setup and Usage
- API Key
- Key Concepts
- Contributing
- License
- Acknowledgments
This project provides a user-friendly interface to check the current weather conditions. Users can enter a city name, and the app will retrieve and display relevant weather information, including temperature, weather description, humidity, wind speed, and an icon representing the weather condition.
- Retrieves current weather data for a specified city.
- Displays temperature in Celsius/Fahrenheit (toggleable).
- Shows weather description (e.g., "Clear sky," "Light rain").
- Displays humidity and wind speed.
- Provides a weather icon representing the current conditions.
- Handles errors gracefully (e.g., city not found).
- Basic styling for a clean and readable interface.
- HTML: For structuring the web page.
- CSS: For styling the application.
- JavaScript: For fetching data from the API and manipulating the DOM.
- OpenWeatherMap API: For retrieving weather data.
-
Clone the repository:
git clone [invalid URL removed]
-
Open the
index.htmlfile in your web browser. -
Enter a city name in the input field and press Enter or click the search button.
This application requires an API key from OpenWeatherMap.
-
Create a free account at OpenWeatherMap.
-
Obtain your API key from your account dashboard (API keys tab).
-
Important: For this project, you'll likely embed the API key directly in your JavaScript file (not recommended for production apps). A better approach for production would be to use a backend server to proxy the API requests. For this simple project, you can add your API key like this inside your JavaScript:
const apiKey = "YOUR_API_KEY"; // Replace with your actual API key
Never commit your API key directly to a public repository in a production application.
The Fetch API is used to make HTTP requests to the OpenWeatherMap API. Here's a basic example of how it's used in this project:
const city = "London";
const url = `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}&units=metric`; // Example URL
fetch(url)
.then(response => response.json())
.then(data => {
// Process the weather data
console.log(data);
// ... update the DOM
})
.catch(error => {
console.error("Error fetching weather data:", error);
// ... display an error message
});