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

C22 Olga & Izzy #12

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

C22 Olga & Izzy #12

wants to merge 19 commits into from

Conversation

ihirad
Copy link

@ihirad ihirad commented Dec 5, 2024

No description provided.

Copy link

@mikellewade mikellewade left a comment

Choose a reason for hiding this comment

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

Nice work! Please let me know if there are any questions about the comments made.

Comment on lines +11 to +25
const updateDecreaseTempCount = () => {
--state.tempCount;
refreshUI()
updateTempColorAndLandscape();
};

const updateIncreaseTempCount = () => {
++state.tempCount;
refreshUI();
updateTempColorAndLandscape();
};

const refreshUI = () => {
state.tempValue.textContent = `${state.tempCount}°F`;
};

Choose a reason for hiding this comment

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

Great work on these functions! The only thing I would change is the refreshUI function name. This name makes think that it would be refreshing the entire page when in actuality it is simply updating the text content for the element displaying the temperature.

Comment on lines +32 to +52
switch (true) {
case state.tempCount >= 80:
tempValue.style.color = "red";
newLandscape.textContent = "🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂";
break;
case state.tempCount >= 70:
tempValue.style.color = "orange";
newLandscape.textContent = "🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷";
break;
case state.tempCount >= 60:
tempValue.style.color = "yellow";
newLandscape.textContent = "🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃";
break;
case state.tempCount >= 50:
tempValue.style.color = "green";
newLandscape.textContent = "🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲";
break;
case state.tempCount < 50:
tempValue.style.color = "teal";
newLandscape.textContent = "🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲";
break;

Choose a reason for hiding this comment

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

Nice using the switch syntax for this! Another way to do this is use a loop and a list to do something like this:

const temperatureRanges = [
  { min: 80, color: "red", landscape: "🌵  🐍 🦂 🌵🌵  🐍 🏜 🦂" },
  { min: 70, color: "orange", landscape: "🌸🌿🌼  🌷🌻🌿 ☘️🌱 🌻🌷" },
  { min: 60, color: "salmon", landscape: "🌾🌾 🍃 🪨  🛤 🌾🌾🌾 🍃" },
  { min: 50, color: "green", landscape: "🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲" },
  { min: -Infinity, color: "blue", landscape: "⛄️ ⛄️ ⛄️" }, // Default for temperatures <= 49
];

for (const range of temperatureRanges) {
  if (state.currentTemp >= range.min) {
    tempValueElement.style.color = range.color;
    landscapeElement.textContent = range.landscape;
    break; // Stop once the matching range is found
  }
}

It helps you avoid all the if statements. You do, however, lose some readability. Mainly because the person would need to realize that it utilizes the order retention of a list. Which one do you think you gravitate to and why?

Comment on lines +66 to +69
const resetCityNameInput = () => {
cityNameInput.value = "";
headerCityName.textContent = "";
};

Choose a reason for hiding this comment

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

Shouldn't we also update our state object as well? That way we don't have `state saying one thing and the UI displaying another.


//wave 4
const findTemperature = (coordinates) => {
console.log(coordinates)

Choose a reason for hiding this comment

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

Don't forget to remove console logs like this, you could accidentally leak private data. Also just helps to keep the code clutter free.

})
.catch((error) => {
console.log("error in findTemperature!", error);
throw error;

Choose a reason for hiding this comment

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

Nice work throwing an error, it makes sure that it doesn't propagate through your following functionality.

Comment on lines +92 to +114
const findLatitudeAndLongitude = () => {
let latitude, longitude;
return axios
.get("http://127.0.0.1:5000/location", {
params: {
q: state.cityName,
format: "json",
},
})
.then((response) => {
latitude = response.data[0].lat;
longitude = response.data[0].lon;
console.log("success in findLatitudeAndLongitude!", latitude, longitude);
return {
lat: latitude,
lon: longitude,
};
})
.catch((error) => {
console.log("error in findLatitudeAndLongitude!");
throw error;
});
};

Choose a reason for hiding this comment

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

Great work on this function! Very easy to follow!

Comment on lines +116 to +131
const getTemperature = () => {

return findLatitudeAndLongitude()
.then((coordinates) => {
return findTemperature(coordinates);
})
.then((temp) => {
const fahrenheit = 1.8 * (temp - 273) + 32;
state.tempCount = Math.round(fahrenheit);
refreshUI();
updateTempColorAndLandscape();
})
.catch((error) => {
console.error("Error in getTemperature!");
state.tempValue.textContent = "Enter a valid city"
});

Choose a reason for hiding this comment

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

😍✨

Comment on lines +135 to +162
const updateSky = () => {
const skySelect = document.getElementById('skySelect').value;
const skyContainer = document.getElementById('sky');

skyContainer.textContent = "";

let sky;
let skyBackgroundClass;

switch (skySelect) {
case 'sunny':
sky = '☀️ ☀️ ☀️ ☀️ ☀️ ☀️';
skyBackgroundClass = 'sunny';
break;
case 'cloudy':
sky = '☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️';
skyBackgroundClass = 'cloudy';
break;
case 'rainy':
sky = '🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧';
skyBackgroundClass = 'rainy';
break;
case 'snowy':
sky = '🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨';
skyBackgroundClass = 'snowy';
break;

}

Choose a reason for hiding this comment

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

Same thing about the landscape could apply here.

Comment on lines +175 to +197
const registerEventHandlers = () => {
loadControls();

const decreaseTemp = document.getElementById("decreaseTempControl");
decreaseTemp.addEventListener("click", updateDecreaseTempCount);

const increaseTemp = document.getElementById("increaseTempControl");
increaseTemp.addEventListener("click", updateIncreaseTempCount);

const skySelect = document.getElementById('skySelect');
skySelect.addEventListener('change', updateSky);

const cityNameReset = document.getElementById("cityNameReset");
cityNameReset.addEventListener("click", resetCityNameInput);
cityNameInput.addEventListener("input", updateCityNameInput);

const currentTempButton = document.getElementById("currentTempButton");
currentTempButton.addEventListener("click", getTemperature);

updateTempColorAndLandscape();
};

document.addEventListener('DOMContentLoaded', registerEventHandlers);

Choose a reason for hiding this comment

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

Nice work ensuring that your document was loaded because adding all your functionality!

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