Skip to content

Conversation

@siderdk
Copy link
Owner

@siderdk siderdk commented Jan 17, 2025

Dear Mentor,
This is the initial commit with the fetch and async function.
I am still wrapping my head around the concepts and getting a better grasp.
Still no frontend elements and I apologize for that.
I will keep trying to optimise the code while awaiting your feedback, because there are some elements that repeat and others that I feel are redundant, and that of course is not good.
Thank you again for your precious help.
S. I.

Copy link

@ahmagdy ahmagdy left a comment

Choose a reason for hiding this comment

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

Good work. Added comments about async/await usage


//fetching the recipes and rendering them
let builtInRecipes = []
async function getRecipes() {
Copy link

Choose a reason for hiding this comment

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

try to add try catch to avoid having a failure when you receive an unexpected response or when you're unable to parse the output as json

const response = await fetch(source);
builtInRecipes = await response.json();
const allRecipes = getAllRecipes();
renderRecipeCard(recipesContainer, getAllRecipes());
Copy link

Choose a reason for hiding this comment

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

The function is called getRecipes while you renderRecipeCard here. So, the name doesn't match the job of the function.
Remember that the function should have a single job.
I suggest that you call renderRecipeCard after calling getRecipes

renderRecipeCard(recipesContainer, getAllRecipes());
return allRecipes
}
getRecipes();
Copy link

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.

3 participants