Skip to content

C22- Sunitha and Beenish#14

Open
beenishali693 wants to merge 16 commits intoAda-C22:mainfrom
nelasunitha:main
Open

C22- Sunitha and Beenish#14
beenishali693 wants to merge 16 commits intoAda-C22:mainfrom
nelasunitha:main

Conversation

@beenishali693
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@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.

Looks good! Please review my comments, and let me know if you have any questions. Nice job!

Comment thread src/index.js
state.cityNameReset = document.getElementById('cityNameReset');
};

let temperature;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why have this additional temperature value when there's a tempValue field in your state?

Comment thread src/index.js
state.cityNameReset.addEventListener('click', resetCityName);
};

document.addEventListener('DOMContentLoaded', registerEventHandlers);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Even though we include this script at the end of the HTML file, it's still good practice to wait to kick off the page logic until we get the DOMContentLoaded event, as you did here.

Note that the function doesn't need to be called registerEventHandlers. So we could have had a function, maybe setupPage that calls loadControls and registerEventHandlers (which could now focus exclusively on registering event handlers rather than first loading the controls).

Comment thread src/index.js

const increaseTemp = () => {
++state.tempValue;
document.getElementById('tempValue').textContent = state.tempValue;
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 could have stored a reference to tempValue in the state, just like for the controls we looked up for registering events. It's pretty common to store references both to controls we use for event handling, as well as those where we need to change the output values.

Comment thread src/index.js
++state.tempValue;
document.getElementById('tempValue').textContent = state.tempValue;
temperature = state.tempValue;
changeColorByTemperature(temperature);
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 could pass state.tempValue as the parameter directly.

  changeColorByTemperature(state.tempValue);

Comment thread src/index.js
Comment on lines +51 to +53
document.getElementById('tempValue').textContent = state.tempValue;
temperature = state.tempValue;
changeColorByTemperature(temperature);
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 logic related to updating the UI based on the current state.tempValue to a helper function (maybe publishTemperature). This could be called from both the increase and decrease handlers (as well as anywhere else we want to be certain the UI is in agreement with out current state.tempValue).

Comment thread src/index.js
const changeSky = () => {
let skyOption = state.skySelect.value;
if (skyOption === 'sunny') {
document.body.style.backgroundImage = 'url(../assets/sunny_sky.jpg)';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Prefer to set a class, and then use CSS rules to update individual proerties, such as the backgroung-image and background-size.

Comment thread src/index.js

const changeSky = () => {
let skyOption = state.skySelect.value;
if (skyOption === '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.

How could we simplify this logic if we stored our sky data in a structure something like

    const skyOptions = {
        sunny: 'sunny-sky',
        cloudy: 'cloudy-sky',
        rainy: 'rainy-sky',
        snowy: 'rainy-sky',
    };

which has the displayed sky option as the keys, and a class to apply as the values.

Comment thread src/index.js
cityNameReset: null,
};

const loadControls = () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In addition to looking up the elements on whcih we want to register event handlers, we could also look up the elements we'll use to display values.

Comment thread src/index.js
let temperature;

const changeCityName = () => {
headerCityName.innerText = state.cityNameInput.value;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Prefer textContent rather than innerText.

Comment thread src/index.js
Comment on lines +37 to +39
document.getElementById('tempValue').textContent = state.tempValue;
tempValue.style.color = 'teal';
landscape.textContent = '❄️🥶☃️❄️🥶☃️❄️🥶☃️❄️🥶☃️❄️🥶☃️';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

As mentioned below, we could move the code responsible for updating the UI based on the temperature to a helper that could be called from all the places where we need to refresh the UI based on changes to the temperature.

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.

3 participants