Skip to content

Conversation

@siderdk
Copy link
Owner

@siderdk siderdk commented Jan 10, 2025

Dear mentor,

Please disregard "scripts.js" and only look at "script.js" and note that this pull request includes week2 + week3 assignments.
I have created a new file, since the changes were too important, and I preferred going on a cleaner basis. The only reason the old file is still there is because I still have some old features I'm still migrating.
I am still laking a UI with the css, but I'll focus on that soon.
Thank you again for your precious time and attention.

This is not just homework for me, but it is more and more morphing into a project I'm getting passionate about. (I know I'm still new and naive haha)

@ahmagdy
Copy link

ahmagdy commented Jan 18, 2025

Amazing work!
Added a few comments and suggestions to make it even better :)



//a function to render a preview card for each recipe inside a given container "parent"
const renderRecipeCard = (parent, array) =>{
Copy link

Choose a reason for hiding this comment

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

nitpicking; array is a very generic term. I would call array => receipes

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thank you for pointing this out. It makes much more sense

//a function to render a preview card for each recipe inside a given container "parent"
const renderRecipeCard = (parent, array) =>{
parent.innerHTML = ""
array.forEach((obj)=>{
Copy link

Choose a reason for hiding this comment

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

same here

receipes.forEach( receipe => {})

obj.ingredients.forEach((ingredient) => {
const listItem = document.createElement('li');
listItem.innerText = ingredient.amount > 0
? `${ingredient.amount || ""} ${ingredient.unit || ""} of ${ingredient.name}`
Copy link

Choose a reason for hiding this comment

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

It's a good use of ternary operator. I would suggest however to switch this into an if statement to avoid having to compile a long line in your head to understand the conditions of this ternary operation

parent.appendChild(recipeCard)

//making cards expand on click
recipeCard.addEventListener("click", ()=>{
Copy link

Choose a reason for hiding this comment

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

should we move the content of this click event listener into a separate function?



ingredientSearchBtn.addEventListener("click", (e)=> {
const num = Math.sqrt((parseInt(ingredientNumber.value) ** 2)); // because I'm lazy I am getting the square root of the square of the input, to make sure it's not a negative value
Copy link

Choose a reason for hiding this comment

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

I suggest to do it properly by checking the negative number :)

Copy link
Owner Author

Choose a reason for hiding this comment

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

noted sir 🫡

};
// check for the value if it's an array to handle the case of ingredients
if ( Array.isArray(value)) {
value.forEach((element)=>{
Copy link

Choose a reason for hiding this comment

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

what is an element here? should give it a more concrete name

Copy link
Owner Author

Choose a reason for hiding this comment

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

Same mistake as "array" earlier, I was using names to remind me types, but I will stick to descriptive one from now on




// finding recipes by keywords
Copy link

Choose a reason for hiding this comment

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

Add a more detailed comment here explaining where do you search about the keyword


seconds++;
timeCount.innerText = seconds;
durationUnit.textContent = " seconds";
Copy link

@ahmagdy ahmagdy Jan 18, 2025

Choose a reason for hiding this comment

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

what are you trying to do here?
Another approach you can follow is to have new Date() object to track the date when you started visiting the website and then you compare it to the current date to get the duration (the time difference)

Copy link
Owner Author

Choose a reason for hiding this comment

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

That is a lot smarter than what I was doing. Thanks a million

}

setTimerBtn.addEventListener("click", ()=>{
const timeAmount = Math.sqrt((parseInt(minutesInput.value) ** 2))
Copy link

Choose a reason for hiding this comment

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

timeDurationInMinutes
Why **2?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Same as earlier, just because I didn't want to do a regex for negative numbers. but I will do it proper 🥸


setTimerBtn.addEventListener("click", ()=>{
const timeAmount = Math.sqrt((parseInt(minutesInput.value) ** 2))
const timeInMlSec = timeAmount * 60000 // converting the amount of time to milliseconds
Copy link

Choose a reason for hiding this comment

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

see my comment above.

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