-
Notifications
You must be signed in to change notification settings - Fork 0
Javascript2 week2/soheib #2
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
base: main
Are you sure you want to change the base?
Conversation
|
Amazing work! |
|
|
||
|
|
||
| //a function to render a preview card for each recipe inside a given container "parent" | ||
| const renderRecipeCard = (parent, array) =>{ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)=>{ |
There was a problem hiding this comment.
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}` |
There was a problem hiding this comment.
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", ()=>{ |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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)=>{ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timeDurationInMinutes
Why **2?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my comment above.
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)