A simple weather application that displays the current weather and a 24-hour forecast for any city. The app fetches data from the OpenWeatherMap API and presents it in a user-friendly interface.
- Search for current weather by city name.
- Display of the current temperature, weather description, and weather icon.
- Display of hourly forecasts for the next 24 hours in 3-hour intervals.
- Responsive design with dynamic updates when a new city is searched.
- HTML
- CSS
- JavaScript
- OpenWeatherMap API
Follow these steps to set up the project:
-
Clone the repository:
git clone https://github.com/HanaNazir/weather-app.git cd weather-app
-
Open the project:
Simply open the
index.html
file in your browser or use a local development server. -
Get an API key from OpenWeatherMap:
- Sign up for an account at OpenWeatherMap.
- Go to the "API keys" section and generate a new API key.
-
Add the API key:
-
Open the
script.js
file and replace theapiKey
variable with your own API key:const apiKey = 'YOUR_API_KEY_HERE';
-
-
Run the app:
Open
index.html
in your browser and start searching for cities to view weather data.
- Enter the name of a city in the search box.
- Click the Search button to fetch and display the current weather and hourly forecast.
- The current weather will show the temperature, weather description, and an icon.
- The hourly forecast will display the weather for the next 24 hours (in 3-hour intervals).
weather-app/
├── index.html # The main HTML file for the app
├── style.css # The main CSS file for styling the app
└── script.js # JavaScript file containing the weather data fetching logic
- If the city is not found, the app will display an error message.
- If there are issues with the API (e.g., incorrect API key), appropriate error messages are shown in the console and an alert is triggered.