Skip to content

solution#1742

Open
Kit3AWP wants to merge 1 commit into
mate-academy:masterfrom
Kit3AWP:develop
Open

solution#1742
Kit3AWP wants to merge 1 commit into
mate-academy:masterfrom
Kit3AWP:develop

Conversation

@Kit3AWP
Copy link
Copy Markdown

@Kit3AWP Kit3AWP commented Apr 13, 2026

- [DEMO LINK](https://Kit3AWP.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

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 as document.querySelector('.preview img') or a dedicated class on the main image instead [CHECKLIST ITEM #1].
  • On the line where you call container.addEventListener(...) after const container = document.querySelector('.gallery');, there is no check that container was actually found, so you should guard it with something like if (!container) return; before adding the listener to avoid runtime errors when .gallery is missing [CHECKLIST ITEM #4].
  • Inside the click handler, when you get the new URL from the thumbnail link, use link.getAttribute('href') instead of link.href so that you preserve the original relative path that the tests are likely asserting against rather than an absolute URL, ensuring the main image src matches 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/scripts/main.js
'use strict';

const container = document.querySelector('.gallery');
const mainImage = document.querySelector('img');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread src/scripts/main.js
@@ -1 +1,18 @@
'use strict';

const container = document.querySelector('.gallery');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown

@vadiimvooo vadiimvooo left a comment

Choose a reason for hiding this comment

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

Well done

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