-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #728 from saketh-05/fixes
Added Weatherly Project
- Loading branch information
Showing
8 changed files
with
223 additions
and
2 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover" | ||
/> | ||
<title>Weather</title> | ||
<link href="style.css" rel="stylesheet" /> | ||
</head> | ||
<body> | ||
<form class="inputForm"> | ||
<input type="text" class="inputcity" placeholder="Enter name of City" /> | ||
<button type="submit" onclick="getWeather()">GetWeather</button> | ||
</form> | ||
<div class="display" style="display: none"></div> | ||
<footer class="footer">All Rights Reserved ||</footer> | ||
<!-- @SakethSurya 😜 --> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
const city = document.querySelector(".inputcity"); | ||
|
||
const inputform = document.querySelector(".inputForm"); | ||
|
||
const card = document.querySelector(".display"); | ||
|
||
const apikey = "4ff8a6dd831902dadd5a06c8aca75468"; | ||
|
||
inputform.addEventListener("submit", async (event) => { | ||
event.preventDefault(); | ||
const inputCity = city.value; | ||
|
||
if (inputCity) { | ||
try { | ||
const wdata = await getWeather(inputCity); | ||
displayCard(wdata); | ||
} catch (error) { | ||
dispError(error); | ||
} | ||
} else { | ||
dispError("Please enter a city"); | ||
} | ||
}); | ||
|
||
async function getWeather(city) { | ||
const apifetch = `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apikey}`; | ||
|
||
const response = await fetch(apifetch); | ||
console.log(response); | ||
|
||
if (!response.ok) { | ||
throw new Error("Could not Fetch the weather data"); | ||
} | ||
return response.json(); | ||
} | ||
|
||
function displayCard(data) { | ||
console.log(data); | ||
const { | ||
name: value, | ||
main: { temp, humidity }, | ||
weather: [{ description, id }], | ||
} = data; | ||
|
||
const city = document.createElement("h2"); | ||
const temprature = document.createElement("p"); | ||
const fahrenhiet = document.createElement("p"); | ||
const humidityDisp = document.createElement("p"); | ||
const descrip = document.createElement("p"); | ||
const emoji = document.createElement("p"); | ||
|
||
city.textContent = value; | ||
temprature.textContent = `${(temp - 273.15).toFixed(1)}°C`; | ||
fahrenhiet.textContent = `${(((temp - 273.15) * 9) / 5 + 32).toFixed(1)}°F`; | ||
humidityDisp.textContent = `Humidity: ${humidity}%`; | ||
descrip.textContent = description; | ||
emoji.textContent = getWeatherEmoji(id); | ||
|
||
city.classList.add("city"); | ||
//temprature.classList.add("display"); | ||
//fahrenhiet.classList.add("display"); | ||
humidityDisp.classList.add("humidityDisp"); | ||
descrip.classList.add("decrip"); | ||
emoji.classList.add("emoji"); | ||
|
||
card.textContent = ""; | ||
card.style.display = "flex"; | ||
card.appendChild(city); | ||
card.appendChild(temprature); | ||
card.appendChild(fahrenhiet); | ||
card.appendChild(humidityDisp); | ||
card.appendChild(descrip); | ||
card.appendChild(emoji); | ||
} | ||
|
||
function getWeatherEmoji(weatherId) { | ||
switch (true) { | ||
case weatherId >= 200 && weatherId < 300: | ||
return "⛈️"; | ||
case weatherId >= 300 && weatherId < 400: | ||
return "🌦️"; | ||
case weatherId >= 500 && weatherId < 600: | ||
return "🌧️"; | ||
case weatherId >= 600 && weatherId < 700: | ||
return "🌨️"; | ||
case weatherId == 701: | ||
return "🌁"; | ||
case weatherId == 800: | ||
return "☀️"; | ||
case weatherId > 800: | ||
return "⛅"; | ||
default: | ||
return "❓"; | ||
} | ||
} | ||
|
||
function dispError(message) { | ||
const error = document.createElement("p"); | ||
error.textContent = message; | ||
error.classList.add("errorDisplay"); | ||
|
||
card.textContent = ""; | ||
card.style.display = "flex"; | ||
card.appendChild(error); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
|
||
body{ | ||
margin: 0; | ||
background-color: rgb(32, 54, 151); | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
margin-bottom: 5%; | ||
} | ||
|
||
.inputForm{ | ||
margin: 5%; | ||
} | ||
.display{ | ||
position: relative; | ||
font-size: 2rem; | ||
background:linear-gradient(rgb(216, 202, 202),crimson); | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
padding: 2% 7% 2% 7%; | ||
border-radius: 5px; | ||
box-shadow: 5px 5px 10px 1px rgb(10, 224, 231), | ||
5px 5px 5px 0px rgb(215, 53, 13) , | ||
1px 1px 10px 5px rgb(181, 26, 26) inset; | ||
} | ||
|
||
.city{ | ||
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande'; | ||
} | ||
|
||
.humidityDisp{ | ||
font-family:'Trebuchet MS', 'Lucida Sans Unicode'; | ||
font-size: 35px; | ||
} | ||
|
||
.descrip{ | ||
font-family: 'Lucida Sans Regular', 'Lucida Grande'; | ||
font-size: 35px; | ||
} | ||
|
||
.emoji{ | ||
font-size: 400%; | ||
margin: 0; | ||
} | ||
|
||
.inputcity{ | ||
font-size: 1.8rem; | ||
color: brown; | ||
max-width: 300px; | ||
padding: 5px; | ||
border-radius: 5px; | ||
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande'; | ||
} | ||
|
||
.errorDisplay{ | ||
font-size: 1.8rem; | ||
color: rgb(255, 255, 1); | ||
font-weight: bold; | ||
font-style: italic; | ||
} | ||
|
||
button[type="submit"]{ | ||
font-weight: bold; | ||
cursor: pointer; | ||
font-size: 1.8rem; | ||
background-color: rgb(1, 255, 242); | ||
color: rgb(83, 13, 83); | ||
padding: 5px 10px 5px 10px; | ||
font-family: 'Gill Sans MT'; | ||
border-radius: 7px; | ||
} | ||
button[type="submit"]:hover{ | ||
background-color: rgb(40, 172, 161); | ||
transition: .25s ease-in-out; | ||
} | ||
|
||
.footer{ | ||
font-size: 30px; | ||
color: rgb(255, 255, 0); | ||
margin: 2%; | ||
} | ||
|
||
@media screen and (max-width: 700px){ | ||
.inputForm{ | ||
margin:5%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
|
||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.