Skip to content

solution#1369

Open
jk-npc wants to merge 4 commits intomate-academy:masterfrom
jk-npc:develop
Open

solution#1369
jk-npc wants to merge 4 commits intomate-academy:masterfrom
jk-npc:develop

Conversation

@jk-npc
Copy link
Copy Markdown

@jk-npc jk-npc commented Mar 12, 2026

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

Great job setting up the promises and handling the UI updates. However, there are a few critical issues that need to be addressed. The most significant one is in firstPromise: the rejection timeout continues to run even after the promise is resolved by a click. This causes an unhandled error in the console. You can fix this by storing the ID from setTimeout and clearing it with clearTimeout() inside the click handler.

Additionally, the rejection value for firstPromise should be the exact string 'First promise was rejected', not an Error object, to match the display requirements. Lastly, for all promises, the event listeners should be removed using removeEventListener() once the promise is settled to prevent memory leaks and unnecessary processing. Addressing these points will make your solution solid.


✨ 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 Outdated

/** first promise */
const firstPromise = new Promise((resolve, reject) => {
document.addEventListener('click', (e) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It's good practice to remove this event listener once the promise is settled (either resolved or rejected) to avoid it running unnecessarily on subsequent clicks. You can achieve this by defining the listener as a named function and using removeEventListener inside both the resolution and rejection logic.

Comment thread src/scripts/main.js Outdated
}
});

setTimeout(() => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This timeout continues to run even if the promise is resolved by a click. You should store the timeout ID in a variable and clear it inside the click handler using clearTimeout() to prevent an attempt to reject an already settled promise.

Comment thread src/scripts/main.js Outdated
});

setTimeout(() => {
reject(new Error('First promise was rejected'));
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 requirement is for the rejection message to be First promise was rejected. Rejecting with new Error() will cause the text in the UI to be Error: First promise was rejected. Consider rejecting with the exact string required, or extracting the .message property from the error object in your .catch handler.

Comment thread src/scripts/main.js Outdated

/** second promise */
const secondPromise = new Promise((resolve) => {
document.addEventListener('mousedown', (e) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Once this promise resolves, the event listener remains active. It's a good practice to remove it to prevent it from running on future clicks. You can define the listener as a named function and call removeEventListener right after resolving the promise.

Comment thread src/scripts/main.js Outdated
let leftClick = false;
let rightClick = false;

document.addEventListener('mousedown', (e) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This event listener remains active even after the promise resolves. Consider removing it inside the if (leftClick && rightClick) block to clean up resources and prevent further executions.

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

Great progress on this! You've successfully addressed the main issues from the last review, like clearing the timeout and removing event listeners. I am requesting one small but important change before this can be approved. The firstPromise is currently rejecting with an Error object, which causes the notification to display 'Error: First promise was rejected'. The requirement is for the exact message 'First promise was rejected'. To fix this, please change your rejection from reject(new Error('First promise was rejected')) to reject('First promise was rejected') in src/scripts/main.js. Once that's updated, this will be ready to go!


✨ 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 Outdated
const timer = setTimeout(() => {
document.removeEventListener('click', handleClick);

reject(new Error('First promise was rejected'));
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 task requires the promise to be rejected with the message 'First promise was rejected'. When you reject with new Error(...), the value caught in the .catch() block is an Error object. When this object is assigned to div.textContent, it's converted to a string, resulting in the text 'Error: First promise was rejected'. To match the requirements exactly, you should reject with the string itself.

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 approving your solution as an educational override so you can move forward, but please take a moment to review this important feedback. You've done a great job implementing the logic for the second and third promises and correctly handling the event listeners! The one critical issue remaining from the last review is that firstPromise must be rejected with a specific string value, not an Error object. To meet the requirement, you would need to change reject(new Error('First promise was rejected')) to reject('First promise was rejected'). Paying close attention to such specific requirements is a key skill. Great work on the rest of the task!


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

Footnotes

  1. Rate AI review example

Comment thread src/scripts/main.js Outdated
const timer = setTimeout(() => {
document.removeEventListener('click', handleClick);

reject(new Error('First promise was rejected'));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This was the issue raised in the previous review. The promise must be rejected with the exact string 'First promise was rejected', not an Error object, to meet the task's requirements.

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