Added a weather app to fetch and display weather by city name#328
Added a weather app to fetch and display weather by city name#328sumn2u merged 6 commits intosumn2u:mainfrom
Conversation
|
@ArshadShaik07 is attempting to deploy a commit to the Suman Kunwar's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@ArshadShaik07 The solution looks great! Would it be possible to place it inside a folder (weather app)? That way, we can easily add more examples later. |
|
yeah sure. |
|
What about now? |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull Request Overview
This PR adds a weather application that allows users to fetch and display weather information by entering a city name. The app uses the OpenWeatherMap API to retrieve weather data and presents it in a responsive web interface.
- Implements weather data fetching from OpenWeatherMap API
- Creates responsive UI with input field, search button, and weather display sections
- Handles user interactions including button clicks and Enter key press
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| examples/Weather-app/index.html | HTML structure with input field, search button, and weather display containers |
| examples/Weather-app/script.js | JavaScript functionality for API calls, DOM manipulation, and event handling |
| examples/Weather-app/styles.css | CSS styling for responsive design and modern UI appearance |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| const btn = document.querySelector(".srch-btn"); | ||
| const cityOp = document.querySelector(".city-name-output"); | ||
|
|
||
| const apiKey = "6244ab888f079565d5ce1deabddc3f77"; |
There was a problem hiding this comment.
API key is hardcoded and exposed in the client-side code. This key should be moved to environment variables or a secure backend service to prevent unauthorized usage.
| ); | ||
| console.log(res); | ||
| if (!res.ok) { | ||
| throw Error("Error occured.Could not find the city "); |
There was a problem hiding this comment.
Corrected spelling of 'occured' to 'occurred'.
| throw Error("Error occured.Could not find the city "); | |
| throw Error("Error occurred. Could not find the city "); |
| windspeed.innerHTML = s; | ||
| temp.innerHTML = t + "<sup>o</sup>C" + `<p>${desc}</p>`; | ||
| humidity.innerHTML = h; | ||
| feels_like.innerHTML = fl + "<sup>o</sup>C"; |
There was a problem hiding this comment.
Using innerHTML with dynamic content can lead to XSS vulnerabilities. Consider using textContent or properly sanitizing the content before insertion.
| feels_like.innerHTML = fl + "<sup>o</sup>C"; | |
| feels_like.textContent = fl; | |
| const sup = document.createElement("sup"); | |
| sup.textContent = "o"; | |
| feels_like.appendChild(sup); | |
| feels_like.appendChild(document.createTextNode("C")); |
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Document</title> |
There was a problem hiding this comment.
The page title should be more descriptive than 'Document'. Consider changing it to 'Weather App' to match the application's purpose.
| <title>Document</title> | |
| <title>Weather App</title> |
| window.addEventListener("load", () => { | ||
| getWeatherInfo("kurnool"); | ||
| }); |
There was a problem hiding this comment.
[nitpick] The hardcoded default city 'kurnool' should be configurable or removed. Consider using a more universally recognizable default city or removing the default load behavior.
| window.addEventListener("load", () => { | |
| getWeatherInfo("kurnool"); | |
| }); |
|
Thank you . |
|
@ArshadShaik07 When you have time, can you look into above suggestions? |
|
Sure . |
|
I have made the modifications according to your suggestions @sumn2u .Kindly check it once |
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| windspeed.innerHTML = s; | ||
| temp.innerHTML = t + "<sup>o</sup>C" + `<p>${desc}</p>`; | ||
| humidity.innerHTML = h; | ||
| feels_like.innerHTML = fl + "<sup>o</sup>C"; | ||
| cityOp.innerHTML = n; | ||
| // Use textContent to prevent XSS vulnerabilities | ||
| windspeed.textContent = s; | ||
| humidity.textContent = h; | ||
| cityOp.textContent = n; |
There was a problem hiding this comment.
Lines 52-56 set innerHTML values that are immediately overwritten by textContent assignments in lines 58-60. The initial innerHTML assignments are redundant and should be removed.
| if (res.status === 404) { | ||
| throw Error("City not found"); | ||
| } else if (res.status === 401) { | ||
| throw Error("Access denied.Check your api key "); |
There was a problem hiding this comment.
Missing space after period in error message. Should be 'Access denied. Check your api key'.
| throw Error("Access denied.Check your api key "); | |
| throw Error("Access denied. Check your api key"); |
| // IMPORTANT: Replace "YOUR_API_KEY" with your actual OpenWeatherMap API key. | ||
| const apiKey = "YOUR_API_KEY"; | ||
| async function getWeatherInfo(city) { | ||
| try { | ||
| console.log(city); |
There was a problem hiding this comment.
API key is hardcoded as a placeholder string. This should be moved to environment variables or a configuration file to prevent accidental exposure in version control.
| // IMPORTANT: Replace "YOUR_API_KEY" with your actual OpenWeatherMap API key. | |
| const apiKey = "YOUR_API_KEY"; | |
| async function getWeatherInfo(city) { | |
| try { | |
| console.log(city); | |
| // IMPORTANT: Set your OpenWeatherMap API key as a global variable before this script runs. | |
| // Example: <script>window.OPENWEATHERMAP_API_KEY = "your_actual_api_key";</script> | |
| const apiKey = window.OPENWEATHERMAP_API_KEY; | |
| async function getWeatherInfo(city) { | |
| console.log(city); | |
| if (!apiKey) { | |
| throw Error("API key is not set. Please set window.OPENWEATHERMAP_API_KEY before loading this script."); | |
| } |
|
Fixes #327 |

This PR adds a simple weather app that allows users to check the weather based on a city name input.
Features:
This project demonstrates API fetching, DOM manipulation, and basic JavaScript usage.