add task solution#1758
Conversation
zubchenko-maksym
commented
Apr 30, 2026
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
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
| if (ev.target.tagName === 'IMG') { | ||
| link = ev.target.parentElement; |
There was a problem hiding this comment.
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.
| list.addEventListener('click', (ev) => { | ||
| ev.preventDefault(); | ||
|
|
||
| let link = ev.target.parentElement; |
There was a problem hiding this comment.
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.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
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! ✨