Skip to content

Conversation

@rochellew23
Copy link

No description provided.

const natureButton = document.getElementById('nature');
const animalButton = document.getElementById('animals');
//filer classes
const all_photos = document.getElementsByClassName('all');

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.

Copy link
Author

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'){

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.

Copy link
Author

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.

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