Skip to content

Sea Turtles Weather Report Tyrah G.#73

Open
ursaturnine wants to merge 7 commits into
ada-c17:mainfrom
ursaturnine:main
Open

Sea Turtles Weather Report Tyrah G.#73
ursaturnine wants to merge 7 commits into
ada-c17:mainfrom
ursaturnine:main

Conversation

@ursaturnine

Copy link
Copy Markdown

No description provided.

@anselrognlie anselrognlie left a comment

Copy link
Copy Markdown

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.

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

Copy link
Copy Markdown

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.

Comment thread index.html
</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>

Copy link
Copy Markdown

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.

Comment thread index.html
</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>

Copy link
Copy Markdown

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.

Comment thread src/index.js
//attach event
upArrow.addEventListener('click', addTemp);
downArrow.addEventListener('click', subtractTemp);
searchBtn.addEventListener('click', cityDisplay);

Copy link
Copy Markdown

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.

Comment thread styles/index.css
}

.landscape{
margin-left: 21cm;

Copy link
Copy Markdown

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.

Comment thread src/index.js
})
.then((response) => {
let temp = response.data.current.temp;
temp = Math.floor(1.8 * (temp - 273) + 32);

Copy link
Copy Markdown

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.

Comment thread src/index.js
let latitude = response.data[0].lat;
let longitude = response.data[0].lon;

getWeather(latitude, longitude);

Copy link
Copy Markdown

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))
};

Comment thread src/index.js

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

Copy link
Copy Markdown

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!

Comment thread src/index.js
}
let sky = document.querySelector('#sky-selector');
let selectedSky = sky.options[sky.selectedIndex].text;
if (selectedSky === 'Sunny') {

Copy link
Copy Markdown

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)!

Comment thread src/index.js
getLatandLon(document.querySelector('.textBox').value);
};

const refreshCity = () => {

Copy link
Copy Markdown

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