-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
weather-report panthers Tiffany Rogers #90
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +0,0 @@ | ||
{ | ||
"singleQuote": true, | ||
"semi": true | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,96 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link rel="stylesheet" href="./styles/index.css" /> | ||
<title>Weather Report</title> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> | ||
</head> | ||
<body> | ||
<!-- weather garden --> | ||
<section id="garden-container"> | ||
<header id="sky-dropdown"> | ||
<div class="seasons" id="Sunny">😎S☀️u🌞n🌅n🌞y😎</div> | ||
<div class="seasons" id="Rainy">🌈R🌧a⛈i💧n🌦y🌈</div> | ||
<div class="seasons" id="Cloudy">☁️C🌥l⛅️o🌤u⛅️d🌥y☁️</div> | ||
<div class="seasons" id="Snowy">❄️S🌨n❅o❆w🌨y❄️</div> | ||
</header> | ||
<div></div> | ||
<footer id="landscape"> | ||
<div class="seasons" id="summer">⛱S🍉u👙m🧴m🩳e🍉r⛱</div> | ||
<div class="seasons" id="spring">🌷S🌸p🌼r🌱i🌼n🌸g🌷</div> | ||
<div class="seasons" id="fall">🍂A🍁u👻t🎃u👻m🍁n🍂</div> | ||
<div class="seasons" id="winter">⛄️W🎿i🛷n🧤t⛸e🧣r⛄️</div> | ||
</footer> | ||
</section> | ||
<!---------------------> | ||
<section> | ||
<!-- header for input weather cards --> | ||
<header id="weather-cards-header"> | ||
<h1>Weather Report</h1> | ||
<h4 style="margin-top: -1rem"> | ||
For the lovely city of <span id="city-name"></span> | ||
</h4> | ||
</header> | ||
<!--------------------------------------> | ||
<!-- input weather cards --> | ||
<section | ||
style=" | ||
display: flex; | ||
align-items: center; | ||
gap: 5rem; | ||
justify-content: center; | ||
" | ||
> | ||
<div class="card" id="card1"> | ||
<button class="button" id="up-arrow">Increment</button> | ||
<h3><span id="temp"></span>°F</h3> | ||
<button class="button" id="down-arrow">Decrement</button> | ||
</div> | ||
<div class="card" id="card2"> | ||
<div style="display: flex; flex-direction: column; gap: 0.5rem"> | ||
<h3>Sky</h3> | ||
<select id="sky-dropdown"> | ||
<option>Select Conditions</option> | ||
<option>Sunny</option> | ||
<option>Rainy</option> | ||
<option>Cloudy</option> | ||
<option>Snowy</option> | ||
</select> | ||
</div> | ||
</div> | ||
<div class="card" id="card3"> | ||
<h1>Search a City</h1> | ||
<label for="city-search">City Name</label> | ||
<input type="text" id="city-search" value="Columbus" /> | ||
<button | ||
style=" | ||
background-color: red; | ||
font-weight: 900; | ||
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, | ||
sans-serif; | ||
color: white; | ||
border-radius: 40px; | ||
width: 10rem; | ||
padding: 1rem; | ||
font-size: 1.5rem; | ||
" | ||
id="get-weather-btn" | ||
> | ||
Get Weather | ||
</button> | ||
<button id="reset-btn">Reset Search</button> | ||
</div> | ||
</section> | ||
<!-------------------------> | ||
</section> | ||
<!-- footer for page --> | ||
<footer> | ||
<h4>By Tiffany Rogers</h4> | ||
</footer> | ||
<!---------------------> | ||
<script type="module" src="./src/index.js"></script> | ||
<script src="./node_modules/axios/dist/axios.min.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
|
||
{ | ||
"dependencies": { | ||
"axios": "^0.27.2" | ||
"axios": "^1.2.1" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
// Accessing DOM/HTML Elements | ||
|
||
const upArrow=document.getElementById("up-arrow"); | ||
const downArrow=document.getElementById("down-arrow"); | ||
const temperature=document.getElementById("temp"); | ||
const summer=document.getElementById("summer"); | ||
const spring=document.getElementById("spring"); | ||
const fall=document.getElementById("fall"); | ||
const winter=document.getElementById("winter"); | ||
const cityName=document.getElementById("city-name"); | ||
const userSearch=document.getElementById("city-search"); | ||
const callApiBtn=document.getElementById("real-temp-btn"); | ||
const resetCityBtn=document.getElementById("reset-btn"); | ||
const getWeatherBtn=document.getElementById("get-weather-btn"); | ||
const skyDropDown=document.getElementById('sky-dropdown'); | ||
const Sunny=document.getElementById('sunny'); | ||
const Snowy=document.getElementById('snowy'); | ||
const Rainy=document.getElementById('rainy'); | ||
const Cloudy=document.getElementById('cloudy'); | ||
const defaultSky=document.getElementById('default-sky'); | ||
|
||
// --------------------------- | ||
|
||
let temp=0; | ||
colors(); | ||
getApi(); | ||
|
||
function getApi() { | ||
let latitude; | ||
let longitude; | ||
axios | ||
.get(`http://127.0.0.1:5000/location?q=${userSearch.value}`) | ||
.then(function apiResponse(response) { | ||
latitude = response.data[0].lat; | ||
longitude = response.data[0].lon; | ||
|
||
axios | ||
.get(`http://127.0.0.1:5000/weather?&lat=${latitude}&lon=${longitude}`) | ||
.then((res) => { | ||
const fahrenheitConversion = Math.floor( | ||
((res.data.main.temp - 273.15) * 9) / 5 + 32); | ||
temperature.textContent = fahrenheitConversion; | ||
temp = fahrenheitConversion; | ||
seasonChange() | ||
}) | ||
}) | ||
.catch((error) => { | ||
alert(error); | ||
}) | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice promise chaining for these functions, Tiffany! I have one refactoring advice for you and that is to implement the const getAPI = async () => {
let lat, long;
try {
const response = await axios.get('http://127.0.0.1:5000/location', {
params: {
q: userSearch.value,
format: 'json',
}})
lat = response.data[0].lat;
long = response.data[0].lon;
getWeather(lat, long)
} catch (err) {
console.log(err);
}
} Using the |
||
|
||
temperature.textContent = temp | ||
|
||
function increment(){ | ||
temp += 1; | ||
temperature.textContent=temp | ||
console.log(temp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remember to remove your console.logs before pushing into production! |
||
colors() | ||
seasonChange() | ||
}; | ||
|
||
function decrement(){ | ||
temp -= 1; | ||
temperature.textContent=temp | ||
console.log(temp) | ||
colors() | ||
seasonChange() | ||
}; | ||
|
||
function colors(){ | ||
if (temp >= 90){ | ||
temperature.style.color="#ab0000" | ||
}else if (temp <= 89 && temp >= 80){ | ||
temperature.style.color="red" | ||
}else if (temp <= 79 && temp >= 70){ | ||
temperature.style.color="orange" | ||
}else if (temp <= 69 && temp >= 60){ | ||
temperature.style.color="green" | ||
}else if (temp <= 59 && temp >= 50){ | ||
temperature.style.color="#38f9cc" | ||
}else if (temp <= 49 && temp >= 40){ | ||
temperature.style.color="#378aea" | ||
}else if (temp <= 39 && temp >= 30){ | ||
temperature.style.color="blue" | ||
}else { | ||
temperature.style.color="#1100ab" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So here you have the right idea for your if statements, however you could just put this here: if (temp > 60) |
||
}; | ||
|
||
function seasonChange(){ | ||
if (temp >= 80){ | ||
summer.style.display="flex" | ||
spring.style.display="none" | ||
fall.style.display="none" | ||
winter.style.display="none" | ||
}else if (temp >= 65){ | ||
summer.style.display="none" | ||
spring.style.display="flex" | ||
fall.style.display="none" | ||
winter.style.display="none" | ||
}else if (temp >= 45){ | ||
summer.style.display="none" | ||
spring.style.display="none" | ||
fall.style.display="flex" | ||
winter.style.display="none" | ||
}else if (temp <= 44){ | ||
summer.style.display="none" | ||
spring.style.display="none" | ||
fall.style.display="none" | ||
winter.style.display="flex" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So here, the refactor that I would suggest would start in the HTML file. Instead of putting all the landscapes I would just put one of them. Something like : const landscape = document.getElementById('landscape')
if (temp >= 65) {
landscape.innerHTML = 😎S☀️u🌞n🌅n🌞y😎
} This way you can save your fingers from typing a lot more code! I would do the same thing in the |
||
}; | ||
|
||
// Func for users city search and display name | ||
function displayInput() { | ||
cityName.textContent = userSearch.value; | ||
} | ||
|
||
function resetCity() { | ||
userSearch.value = 'Columbus'; | ||
cityName.textContent = 'Columbus'; | ||
getApi(); | ||
} | ||
|
||
displayInput() | ||
seasonChange() | ||
|
||
|
||
// Function for getting value of sky/conditions dropdown | ||
function dropdownValue() { | ||
console.log(skyDropDown.value); | ||
console.log('1'); | ||
// if(skyDropDown.value === 'Select Conditions'){ | ||
// sunnySky.style.display = 'none'; | ||
// cloudySky.style.display = 'none'; | ||
// rainySky.style.display = 'none'; | ||
// snowSky.style.display = 'none'; | ||
// defaultSky.style.display = 'block'; | ||
} if (skyDropDown.value === 'Sunny'){ | ||
Sunny.style.display = 'block' | ||
Cloudy.style.display = 'none'; | ||
Rainy.style.display = 'none'; | ||
Snowy.style.display = 'none'; | ||
defaultSky.style.display = 'none'; | ||
} else if (skyDropDown.value === 'Rainy') { | ||
Sunny.style.display = 'none' | ||
Cloudy.style.display = 'none'; | ||
Rainy.style.display = 'block'; | ||
Snowy.style.display = 'none'; | ||
defaultSky.style.display = 'none'; | ||
} else if (skyDropDown.value === 'Cloudy') { | ||
Sunny.style.display = 'none' | ||
Cloudy.style.display = 'none'; | ||
Rainy.style.display = 'none'; | ||
Snowy.style.display = 'block'; | ||
defaultSky.style.display = 'none'; | ||
} else if (skyDropDown.value === 'Snowy') { | ||
Sunny.style.display = 'none'; | ||
Cloudy.style.display = 'none'; | ||
Rainy.style.display = 'none'; | ||
Snowy.style.display = 'block'; | ||
defaultSky.style.display = 'none'; | ||
}; | ||
|
||
dropdownValue() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see you are invoking the certain functions in order to get the intital data displayed on the first render of the page. I would just move these all somewhere together. Given that you used the |
||
|
||
upArrow.addEventListener('click', increment); | ||
downArrow.addEventListener('click', decrement); | ||
resetCityBtn.addEventListener('click', resetCity); | ||
getWeatherBtn.addEventListener('click', getApi); | ||
userSearch.addEventListener('input', displayInput); | ||
skyDropDown.addEventListener('change', dropdownValue); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here the only suggestion is to move these inside a |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#weather-cards-header{ | ||
text-align: center; | ||
font-size: 2rem; | ||
color:crimson | ||
} | ||
|
||
.card { | ||
border:1.5px solid black; | ||
padding:1rem 1rem | ||
} | ||
|
||
#card1{ | ||
min-width: 15%; | ||
min-height: 15%; | ||
} | ||
|
||
#temp{ | ||
font-size: 6rem; | ||
} | ||
|
||
.seasons{ | ||
font-size: 120px; | ||
justify-content: center; | ||
} | ||
|
||
#garden-container{ | ||
background-color: aqua; | ||
text-align: center; | ||
} | ||
footer{ | ||
text-align: center; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All in all, great work Tiffany! ✨ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When doing this much styling it is best to move it inside of your css file so it doesn't congest your html files.