Skip to content

JSON and APIs Eval#212

Open
acl13 wants to merge 13 commits intoprojectshft:masterfrom
acl13:master
Open

JSON and APIs Eval#212
acl13 wants to merge 13 commits intoprojectshft:masterfrom
acl13:master

Conversation

@acl13
Copy link

@acl13 acl13 commented Aug 6, 2024

No description provided.

main.js Outdated
@@ -0,0 +1,117 @@
document.getElementById("search").addEventListener("click", function () {
const userSearch = document.getElementById("search-query").value;
console.log(userSearch);

Choose a reason for hiding this comment

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

remove console logs

main.js Outdated
const userSearch = document.getElementById("search-query").value;
console.log(userSearch);

if (userSearch === "") {

Choose a reason for hiding this comment

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

same as the other project, this is not a good validation. Empty spaces make the api call

fetchWeatherData(userSearch);
}

document.getElementById("search-query").value = "";

Choose a reason for hiding this comment

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

for readability, you can extract this to a separate function like:

Suggested change
document.getElementById("search-query").value = "";
const resetSearchInput() => {
document.getElementById("search-query").value = "";
}

main.js Outdated
};

function handleError(error) {
console.log(`ERROR: ${error}`);

Choose a reason for hiding this comment

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

this is a good start but ideally you want to display a message in the html alerting the user he entered a wrong city or that there was a server error.

main.js Outdated

// Weekdays listed twice to account for overlap
const date = new Date();
const days = [

Choose a reason for hiding this comment

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

This is fixed, dont need to be recreated each time you call displayForecast, you can define on top of the file

main.js Outdated
const dayThree = data.list[23];
const dayFour = data.list[31];
const dayFive = data.list[39];
const forecastDisplay = [dayOne, dayTwo, dayThree, dayFour, dayFive];

Choose a reason for hiding this comment

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

DRY, can you think of a more efficient (less lines of code) to do this using an array helped method?
hint, map :)

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