-
Notifications
You must be signed in to change notification settings - Fork 18
rochelle williams week 3 hw #5
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
| const natureButton = document.getElementById('nature'); | ||
| const animalButton = document.getElementById('animals'); | ||
| //filer classes | ||
| const all_photos = document.getElementsByClassName('all'); |
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.
Hi Rochelle, you may want to test out your page again. When you click the "All" and "Nature" filters, it works correctly, but when you click the "City" and "Animals" filters, it's either not showing all the correct images or it's not showing any images at all. You may want to take a look where you are creating all the arrays for photo type, because something may be going wrong there.
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 don't why it's not working on your end because it's working on mine, but I changed the photo filter function to use a switch statement like you said in the other comment, so hopefully it works now.
script.js
Outdated
|
|
||
|
|
||
| function filterPhotos(keyword){ | ||
| if (keyword == 'city'){ |
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.
This is a great opportunity to use a switch statement, like we've looked at in class.
Also, instead of having to create a for loop for every array and hiding the element, why not use your all_photos array to hide all the photos, and then loop through the array of the photo type that was selected. This would clean up your code a lot.
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 added the switch statement, and it does look a lot neater. When I first learned JavaScript I wasn't taught about switch statements so it completely slipped my mind.
No description provided.