Skip to content

add task solution#1758

Open
zubchenko-maksym wants to merge 2 commits intomate-academy:masterfrom
zubchenko-maksym:develop
Open

add task solution#1758
zubchenko-maksym wants to merge 2 commits intomate-academy:masterfrom
zubchenko-maksym:develop

Conversation

@zubchenko-maksym
Copy link
Copy Markdown

- [DEMO LINK](https://zubchenko-maksym.github.io/js_gallery_DOM/)

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

The code has a critical logic error that prevents the gallery from working when clicking directly on <a> elements. When ev.target is an <a> tag (not an <img>), link is incorrectly set to ev.target.parentElement instead of ev.target, causing the link.tagName !== 'A' check to fail and return early. Additionally, link = ev.target.parentElement is set unconditionally before the if (ev.target.tagName === 'IMG') check, making it dead code when the condition is true. To fix this: initialize link = ev.target before the condition, then use if/else to set link = ev.target.parentElement only when the target is an <img> element, and keep link as ev.target in the else branch for <a> elements.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/scripts/main.js
Comment on lines +11 to +12
if (ev.target.tagName === 'IMG') {
link = ev.target.parentElement;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The condition if (ev.target.tagName === 'IMG') is redundant because line 12 executes the same assignment as line 9. This check needs to be changed to an else branch to handle the case when event.target is an <a> element.

Comment thread src/scripts/main.js Outdated
list.addEventListener('click', (ev) => {
ev.preventDefault();

let link = ev.target.parentElement;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When clicking directly on an <a> element (not on an <img> inside it), ev.target will be the <a> itself. However, this line sets link to ev.target.parentElement which would be the <li>, not the <a>. This causes the gallery to fail when clicking on anchors outside of images.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

Your image gallery implementation is approved and meets all requirements. The code correctly uses event delegation on the ul element, properly handles both img and a click targets with the if/else if/else structure, and successfully updates the main image source when thumbnails are clicked. The README also contains the correct DEMO LINK with your GitHub username. All checklist items pass, and no critical issues were found. Great work implementing the functionality exactly as specified!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

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.

2 participants