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 Sphinx - Aleida Vieyra + Vlada Rapaport #21

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

Conversation

aleidavi
Copy link

@aleidavi aleidavi commented Dec 6, 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.

</head>

Choose a reason for hiding this comment

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

The spacing is being used for readability and separating different parts of the page, this is fine for me. Just be mindful that some developers might prefer for there to be no empty spaces.

const updateTemperatureDisplay = () => {
const tempValueElement = document.getElementById("tempValue");
const landscapeElement = document.getElementById("landscape");
tempValueElement.textContent = `${state.currentTemp}°`;

Choose a reason for hiding this comment

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

I want to say that this could just be of the type Number and it would still work so the `` wouldn't be necessary.

Comment on lines +17 to +32
if (state.currentTemp >= 80) {
tempValueElement.style.color = "red";
landscapeElement.textContent = "🌵 🐍 🦂 🌵🌵 🐍 🏜 🦂";
} else if (state.currentTemp >= 70) {
tempValueElement.style.color = "orange";
landscapeElement.textContent = "🌸🌿🌼 🌷🌻🌿 ☘️🌱 🌻🌷";
} else if (state.currentTemp >= 60) {
tempValueElement.style.color = "salmon";
landscapeElement.textContent = "🌾🌾 🍃 🪨 🛤 🌾🌾🌾 🍃";
} else if (state.currentTemp >= 50) {
tempValueElement.style.color = "green";
landscapeElement.textContent = "🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲";
} else if (state.currentTemp <= 49) {
tempValueElement.style.color = "blue";
landscapeElement.textContent = "⛄️ ⛄️ ⛄️";
}

Choose a reason for hiding this comment

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

To make this a little more concise and avoid the multiple if statements we could use a loop and a list to do something like this instead:

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

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 +36 to +45
const increaseTemp = () => {
state.currentTemp += 1;
updateTemperatureDisplay();
};

// Function to decrease temperature
const decreaseTemp = () => {
state.currentTemp -= 1;
updateTemperatureDisplay();
};

Choose a reason for hiding this comment

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

⭐️

Comment on lines +48 to +54
const temperatureControls = () => {
const warmUpButton = document.getElementById("increaseTempControl");
const coolDownButton = document.getElementById("decreaseTempControl");

warmUpButton.addEventListener("click", increaseTemp);
coolDownButton.addEventListener("click", decreaseTemp);
};

Choose a reason for hiding this comment

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

Straightforward and correct, no notes!

Comment on lines +100 to +102
console.log(
`Location: ${location}, Latitude: ${latitude}, Longitude: ${longitude}`
);

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.

Comment on lines +90 to +107
return axios
.get("http://127.0.0.1:5000/location", {
params: {
q: location,
},
})
.then((response) => {
let latitude = response.data[0].lat;
let longitude = response.data[0].lon;

console.log(
`Location: ${location}, Latitude: ${latitude}, Longitude: ${longitude}`
);
return {
latitude: latitude,
longitude: longitude,
};
})

Choose a reason for hiding this comment

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

Great work on this promise! Very easy to follow! Especially since you also decided to use different helper functions to tie things together!

Comment on lines +123 to +124
if (!coordinatesResponse) {
throw new Error("Coordinates could not be retrieved.");

Choose a reason for hiding this comment

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

You could also throw this error in the catch above so that the error doesn't propagate further down like it does here.

Comment on lines +150 to +156
getCurrentCityWeather().then((tempKelvin) => {
if (tempKelvin) {
const conversion = (tempKelvin - 273) * (9 / 5) + 32;
state.currentTemp = Math.round(conversion);
updateTemperatureDisplay();
}
});

Choose a reason for hiding this comment

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

Nice chaining! Only suggestion, moving the temperature conversion logic into its own function so that it would be more readable since we are already working inside of a .then chain.

Comment on lines +1 to +5
const state = {
currentTemp: 0,
cityName: "Miami",
defaultCityName: "Seattle",
};

Choose a reason for hiding this comment

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

Nice work on selecting what pieces of data should go in state! I think that these a the quintessential choices! ✨

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