solution#1742
Conversation
Kit3AWP
commented
Apr 13, 2026
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because there are a few issues that can break the gallery behavior or cause tests to fail in realistic page structures. Your overall approach with event delegation and using evt.target.closest('a') is solid, but the implementation is currently a bit too fragile.
- On the line where you set
const mainImage = document.querySelector('img');, this will grab the first<img>on the page, which might be a thumbnail rather than the main preview image, so please select the main image via a more specific selector such asdocument.querySelector('.preview img')or a dedicated class on the main image instead [CHECKLIST ITEM #1]. - On the line where you call
container.addEventListener(...)afterconst container = document.querySelector('.gallery');, there is no check thatcontainerwas actually found, so you should guard it with something likeif (!container) return;before adding the listener to avoid runtime errors when.galleryis missing [CHECKLIST ITEM #4]. - Inside the click handler, when you get the new URL from the thumbnail link, use
link.getAttribute('href')instead oflink.hrefso that you preserve the original relative path that the tests are likely asserting against rather than an absolute URL, ensuring the main imagesrcmatches expectations [CHECKLIST ITEM #1].
Once you address these points, your gallery code should be both robust and aligned with the task requirements, and the rest of your current solution looks good and on the right track.
✨ 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
| 'use strict'; | ||
|
|
||
| const container = document.querySelector('.gallery'); | ||
| const mainImage = document.querySelector('img'); |
There was a problem hiding this comment.
You use document.querySelector('img'), which returns the first in the document. If the first image is a thumbnail, this will update the wrong element. Select the main/preview image explicitly (for example
document.querySelector('.preview img') or give the main image a dedicated class) so tests and different DOM orders behave correctly.
| @@ -1 +1,18 @@ | |||
| 'use strict'; | |||
|
|
|||
| const container = document.querySelector('.gallery'); | |||
There was a problem hiding this comment.
There is no check that container exists before calling addEventListener. If .gallery is missing this will throw. Add a guard like if (!container) return; or check before attaching the listener.