-
Notifications
You must be signed in to change notification settings - Fork 24
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
C22- Sphinx - Weixi He, Nikki Vaughan / Phoenix - Ajar Duishembieva #3
base: main
Are you sure you want to change the base?
Conversation
…ranges to change text color
…lement that allows the user to change the city name
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.
Nice work folks, let me know if you have any question on the feedback! =]
temp.innerText = (value - 1); | ||
} | ||
|
||
const changeSky = () => { |
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.
The Weather Garden's sky will only appear once a user selects an option other than "Sunny" for the first time, even though it looks like a default of "Sunny" is selected. Where could we call this function so the sky is displayed along with the garden when it is updated?
<span>For the lovely city of | ||
<span id="headerCityName" class="header__city-name"></span></span> |
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.
I suggest using something like a h2
or a p
element around the inner span
here.
span
is much like div
where it does not inherently have semantic meaning, so we want to reserve it for places where we need an inline element to wrap something for styling-purposes only. More info: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span
<section class="temperature__section" id="temperatureSection"> | ||
<h2>Temperature</h2> | ||
<div class="temperature__content"> | ||
<div class="temperature__controls"> |
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.
There are some div
s across the HTML like this one that I might suggest replacing with section
or article
elements because it looks they are meaningfully sectioning content. That way we only leave div
s where they are wrapping content for styling purposes.
I suggest taking a look at each div
across the file and asking: if it is doing more work than styling, is there any semantic element that could be a better fit?
const changeColor = (temperature) =>{ | ||
const element = document.getElementById("temperatureSection"); | ||
if(temperature >= 80){ | ||
element.classList.forEach((className) => COLORS.includes(className) ? element.classList.remove(className) : className ) |
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.
Since this line is repeated without change in each if/else block, we can remove it from these blocks and perform the operation just once before the if/else chain starts.
const defaultCity = "Seattle"; | ||
cityTitle.textContent = defaultCity; |
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.
Since we already set a default city, what could it look like to set a default temperature so that a user would have a weather and sky to look at and easily navigate between when the page loads up?
changeColor(value) | ||
temp.innerText = (value + 1); |
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.
increaseTemp
and decreaseTemp
might not be operating exactly as you expect since the color change function gets called before we actually change the temperature value.
When you manually increase the temperature starting at 68, I have to go to 71 before I see the next set of garden emojis appear. The same happens when I decrease from 71, it doesn't change back to the previous garden until the temperature reads 68.
const increaseTemp = () =>{ | ||
value = parseInt(temp.textContent) || 0; | ||
changeColor(value) | ||
temp.innerText = (value + 1); | ||
|
||
} | ||
|
||
const decreaseTemp = () => { | ||
value = parseInt(temp.textContent) || 0; | ||
changeColor(value) | ||
temp.innerText = (value - 1); | ||
} |
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.
Since increaseTemp
and decreaseTemp
are very similar, another approach we could take is to combine them into 1 function:
const setTemp = (changeInTemp) => {
value = parseInt(temp.textContent) || 0;
changeColor(value)
temp.innerText += changeInTemp;
};
Then where we register the handlers, we could call our new function with a parameter by doing so inside an anonymous function:
increment.addEventListener('click', () => { setTemp(1) });
decrement.addEventListener('click', () => { setTemp(-1) });
axios | ||
.get('http://127.0.0.1:5000/location', {params: {q: cityName}}) | ||
.then((response) => { | ||
console.log( |
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.
We should remove console.log
statements from our Javascript before submission just like with print
statements in our Python code.
else if(temperature >= 50 && temperature <=59){ | ||
element.classList.forEach((className) => COLORS.includes(className) ? element.classList.remove(className) : className ) | ||
element.classList.add('green'); | ||
landscape.textContent = '🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲'; | ||
} | ||
else { | ||
element.classList.forEach((className) => COLORS.includes(className) ? element.classList.remove(className) : className ) | ||
element.classList.add('teal'); | ||
landscape.textContent = '🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲'; | ||
} |
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 we have large if-statements like this where each if-block performs the same operations with slightly different values, it can be worth making a helper function that handles the updates to reduce places we're repeating code and could accumulate small typos. With the helper function, each of the ifs here would call that function passing the desired parameters rather than setting attributes themselves.
display: flex; | ||
flex-direction: row; | ||
justify-content: space-around; | ||
/* justify-content: center; */ |
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.
Commented out code should be removed before opening PRs.
No description provided.