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

Sea Turtles Weather Report Tyrah G. #73

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

Conversation

ursaturnine
Copy link

No description provided.

Copy link

@anselrognlie anselrognlie left a comment

Choose a reason for hiding this comment

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

Nice job!

Storing app state in variables is a useful code strategy (get your city name and sky in there too!). Structuring our code so that there are separate functions for updating those variables, and then publishing the values helps us manage user interactions and data processing. Think about how to restructure the axios calls to be a bit more generally reusable (how can we avoid making the second call directly from the first?). And keep an eye out for areas where we can use data structures to reduce code duplication.

</div>
<div class="city">
<form action="#">
<input class='textBox'type='search' placeholder="Search a City" name="q">

Choose a reason for hiding this comment

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

Make sure to leave space between your attributes.

</div>
<script src="./node_modules/axios/dist/axios.min.js"></script>
<script src="https://requirejs.org/docs/release/2.3.5/minified/require.js"></script>
<script src="src/index.js" type="text/javascript"></script>

Choose a reason for hiding this comment

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

text/javascript is the default value for script types, and is usually omitted.

</div>
</div>
<script src="./node_modules/axios/dist/axios.min.js"></script>
<script src="https://requirejs.org/docs/release/2.3.5/minified/require.js"></script>

Choose a reason for hiding this comment

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

What is this external import being used for? I don't see anything "require-y" in the code.

//attach event
upArrow.addEventListener('click', addTemp);
downArrow.addEventListener('click', subtractTemp);
searchBtn.addEventListener('click', cityDisplay);

Choose a reason for hiding this comment

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

We also wanted to have an input handler on the city text box to update the displayed city name in the UI as the user types.

}

.landscape{
margin-left: 21cm;

Choose a reason for hiding this comment

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

I have a hard time wrapping my head around "physical" units in CSS. I tend to stick with pixels, percentages, ems, or some combination of them.

})
.then((response) => {
let temp = response.data.current.temp;
temp = Math.floor(1.8 * (temp - 273) + 32);

Choose a reason for hiding this comment

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

Consider moving this conversion code into a helper function.

let latitude = response.data[0].lat;
let longitude = response.data[0].lon;

getWeather(latitude, longitude);

Choose a reason for hiding this comment

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

Nesting another axios call in the response handler works out OK in this situation since the two calls we're making are pretty small and related, so it makes sense to have them grouped together. But it can also be useful to make these two calls into individual helpers (get the lat/lon for the city, get the weather for the lat/lon), and then combining them in another function. Something like (very loosely):

const getLatLon = (...) => { return axios.get(...) };
const getTemp = (...) => { return axios.get(...) };
const getTempForCity = (...) => {
  return getLatLon(...)
    .then(response => getTemp(response.data.latLonData))
    .then(response => publishTempData(response.data.tempData))
    .catch(err => console.log(err))
};


//change the sky
const changeSky = () => {
let skyOptions = document.querySelector('#skyContainer').children;

Choose a reason for hiding this comment

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

It looks like you went with a similar approach to your landscape changes here. I think that on the whole, I still tend to prefer having the display data defined in the JS, and then have written out to the HTML as needed (greater opportunity to make the display data-driven), but for the selection of skies you have, this works well. It does have the potential to allow richer layouts for they sky than simple text or an image, so I'd be curious to see how far you can push this!

}
let sky = document.querySelector('#sky-selector');
let selectedSky = sky.options[sky.selectedIndex].text;
if (selectedSky === 'Sunny') {

Choose a reason for hiding this comment

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

Like for the temp check, each of these clauses is very repetitive. We look for a matching value to locate information about what values to set in the UI. Consider using object (key) lookups to make this more data-driven. If the values are stored elsewhere (maybe loaded from an api) then the code here would essentially reduce down to a key lookup in an object (sky value -> element id)!

getLatandLon(document.querySelector('.textBox').value);
};

const refreshCity = () => {

Choose a reason for hiding this comment

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

👍

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