Skip to content
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

olive - sea turtles - weather report #84

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

olive-lavine
Copy link

No description provided.

Copy link

@kelsey-steven-ada kelsey-steven-ada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work Olive! I've left some comments & suggestions, take a look when you have time and let me know if there's anything I can clarify =]

<section id = "landscape">
<h1 id="city-name-display">New Orleans</h1>
<button id = "realtime-button"> Realtime Temp</button>
<img id="landscape-img" src="/images/sunny.png" alt="black line drawings of sun, with circle in center"/>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were you able to see the landscape images when viewing the page locally? Using Chrome, I pulled the code down & I could see the image descriptions, but to view the the images I had to add a . in front of the paths so that it was looking for the images folder in the same folder index.html was in.

Comment on lines +19 to +20
state.temp += x;
tempDisplay.textContent = `${state.temp}°`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice placing the temp change that will happen in every scenario at the top so that code isn't repeated.

Comment on lines +18 to +49
const updateTempDisplay = (x) => {
state.temp += x;
tempDisplay.textContent = `${state.temp}°`;

if (state.temp > 79) {
tempDisplay.style.color = 'rgb(248, 163, 163)';
}
if (state.temp < 80) {
tempDisplay.style.color = 'orange';
landscapeImg.src = '/images/sunny.png';
landscapeImg.alt = 'black line drawings of sun, with circle in center';
}
if (state.temp < 70) {
tempDisplay.style.color = 'yellow';
landscapeImg.src = '/images/cloudy.png';
landscapeImg.alt = 'black line drawing of clouds in front of a sun';
}
if (state.temp < 60) {
tempDisplay.style.color = '#2B835E';
}
if (state.temp < 50) {
tempDisplay.style.color = 'teal';
landscapeImg.src = '/images/rainy.png';
landscapeImg.alt =
'black line drawings of cloud with strong diagonal rain falling';
}
if (state.temp < 40) {
tempDisplay.style.color = '#CFF2FF';
landscapeImg.src = '/images/snowy.png';
landscapeImg.alt = 'black line drawings of a detailed snowflake';
}
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to interact with the same items in the various temperature buckets. We could make a helper function that takes in 3 parameters: a color, and image path, and a string for alt text, and that sets those values if they are not falsy.

const updateImgAndColor = (color, imgPath, altText) => {
    if (color) {
        tempDisplay.style.color = color
    }

    ... (and so on for the other 2 parameters)    
}

Then in the if-statements here we could call:

const updateTempDisplay = (x) => {
    ...
    if (state.temp < 60) {
        updateImgAndColor('#2B835E', null, null);
    }
    if (state.temp < 50) {
        updateImgAndColor('teal', '/images/rainy.png', 'black line drawings of cloud with strong diagonal rain falling');
    }
    ...

tempDisplay.textContent = `${state.temp}°`;
tempDisplay.style.color = state.color;

const updateTempDisplay = (x) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should generally avoid single letter variable names in favor of ones that describe what they hold. What name or names are more descriptive of what x represents?

Comment on lines +3 to +6
const tempDisplay = document.getElementById('temp-display');
const landscapeImg = document.getElementById('landscape-img');
const cityName = document.getElementById('city-name-display');
const cityInputBox = document.getElementById('city-name');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of pulling element lookups to the top of the page so they're stored in a variable at the time we need them!

It looks like there's a mix styles across the file with these elements being looked up & stored up here and other elements looked up directly in the functions. For consistency, we would want to pick one style to use across the project, with the caveat that if there is an element that is only conditionally aded to the DOM based on user events, that specific item may need to be looked up later inside a function when it is guaranteed to exist.

Comment on lines +52 to +73

? : An element that displays the temperature
? : A clickable element to increase temperature
?: A clickable element to decrease temperature
?: An element that displays a landscape

Wave 3:

?: An element that displays the city name
?: An element that contains an <input type="text"> element, used to rename the city

Wave 4:

?: A clickable element to get the current temperature of the displayed city name
Wave 5:

?: A <select> dropdown element to set the sky type
?: An element that displays a sky
Wave 6:

?: A clickable element to reset the city name -->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to remove comments and development & debugging aids before we open PRs to make sure we don't accidentally include them into production/shipping code.

tempDisplay.textContent = `${state.temp}°`;

if (state.temp > 79) {
tempDisplay.style.color = 'rgb(248, 163, 163)';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By setting the style attribute directly on an element, we’re doing the javascript equivalent of adding inline CSS styles, which is not considered best practice. The preference would be to create CSS rules for the styles, likely attached to a class name, then set the element's className attribute to the appropriate value for the style we want to attach.

So in our CSS we'd have rule sets:

...

.red {
    color: red;
}

.orange {
    color: orange;
}

... /* (and so on for the other colors necessary) */

And here we'd do something like:

...
if (state.temp >= 80) {
    currentTemp.className = 'red';
...

Comment on lines +121 to +126
const realtimeTemp = async () => {
const place = state.city;
const { lat, lon } = await getLatLon(place);
state.temp = await getTemp(lat, lon);
updateTempDisplay(0);
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of async/await to let you separate the network call functions!

landscapeImg.alt = 'black line drawing of clouds in front of a sun';
}
if (state.temp < 60) {
tempDisplay.style.color = '#2B835E';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In production code we'd likely want to include comments about what the hex colors are, since many folks cannot sight-read hex values.

cityName.textContent = state.city;
};

const resetCity = () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice use of helper functions to divide up the actions we want to take into smaller portions that are easier to read and test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants