├── .gitignore ├── LICENSE ├── README.md ├── app.js ├── index.html └── styles.css /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore node_modules 2 | node_modules/ 3 | 4 | # Ignore log files 5 | npm-debug.log 6 | yarn-error.log 7 | 8 | # Ignore environment variable files 9 | .env 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WeatherChecker 2 | 3 | WeatherChecker is a simple JavaScript-based web application that fetches and displays weather data for a specified location using a public weather API. 4 | 5 | ## Features 6 | 7 | - Fetches current weather data for a specified location. 8 | - Displays temperature, weather condition, and an icon representing the weather. 9 | 10 | ## Installation 11 | 12 | 1. Clone the repository: 13 | ```bash 14 | git clone https://github.com/YOUR_USERNAME/WeatherChecker.git 15 | cd WeatherChecker 16 | ``` 17 | 18 | 2. Open `index.html` in your web browser. 19 | 20 | ## License 21 | 22 | This project is licensed under the MIT License. 23 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | document.getElementById('weather-form').addEventListener('submit', function(e) { 2 | e.preventDefault(); 3 | const location = document.getElementById('location-input').value; 4 | getWeather(location); 5 | }); 6 | 7 | async function getWeather(location) { 8 | const apiKey = 'YOUR_API_KEY'; // Replace with your actual API key 9 | const url = `https://api.openweathermap.org/data/2.5/weather?q=${location}&units=metric&appid=${apiKey}`; 10 | 11 | try { 12 | const response = await fetch(url); 13 | if (!response.ok) { 14 | throw new Error('Location not found'); 15 | } 16 | const data = await response.json(); 17 | displayWeather(data); 18 | } catch (error) { 19 | alert(error.message); 20 | } 21 | } 22 | 23 | function displayWeather(data) { 24 | document.getElementById('location-name').textContent = data.name; 25 | document.getElementById('temperature').textContent = `Temperature: ${data.main.temp}°C`; 26 | document.getElementById('condition').textContent = `Condition: ${data.weather[0].description}`; 27 | document.getElementById('icon').src = `http://openweathermap.org/img/w/${data.weather[0].icon}.png`; 28 | document.getElementById('weather-result').classList.remove('hidden'); 29 | } 30 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |