Weather
Created
July 20, 2023 06:41
-
-
Save NANDHINI7390/e83b68f5c5c5a85f4af5b1f736eab1ec to your computer and use it in GitHub Desktop.
Weather api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1 style="color:#148F77 "><b><i><center> Weather App🌡 </i></b></center></h1> | |
<center><input type='search' placeholder='enter the city ' id="city" class="search-bx" name='cityname'style= "width:50%;background-color: white;padding: 12px 20px;margin: 10px 0;display: inline-block;border: 1px solid green;border-radius: 6px;box-sizing: content-box "></center> | |
<br> | |
<center><button id="search-button" style="color: yellow; background-color: grey">search</button><center> | |
<br> | |
<div> | |
<div id="location " ></div> | |
<div id="temp" ></div> | |
</div> | |
<div > | |
<div id="weather"></div> | |
<div id="min-max" ></div> | |
</div> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let city=document.querySelector(".search-bx") | |
const searchButton=document.getElementById("search-button") | |
const apiData = { | |
url: `https://api.openweathermap.org/data/2.5/weather?q=`, | |
key: `9b81d3e4265e2d1a5b8b73f1591ec139`, | |
}; | |
async function getWeather(countryName) { | |
//console.log(searchBox.value) | |
const response =await fetch(`${apiData.url}${countryName}&appid=${apiData.key}`) | |
var data=await response.json(); | |
console.log(data) | |
document.getElementById ("location "). innerText=`${data.name}, ${data.sys.country}`; | |
document.getElementById ("temp").innerText=`${Math.floor(data.main.temp - 273.15)} °c`; | |
document.getElementById ("weather").innerText=`${data.weather[0].main}`; | |
document.getElementById ("min-max"). innerText=`${Math.floor(data.main.temp_min - 273.15)} °c/${Math.floor(data.main.temp_max - 273.15)} °c`; | |
console.log (data.sys.country) | |
} ; | |
function searchData() { | |
const cityName=city.value; | |
console.log (cityName) ; | |
getWeather(cityName); | |
} | |
searchButton.addEventListener("click", searchData) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment