Skip to content

solve#1365

Open
Teti-web wants to merge 4 commits intomate-academy:masterfrom
Teti-web:develop
Open

solve#1365
Teti-web wants to merge 4 commits intomate-academy:masterfrom
Teti-web:develop

Conversation

@Teti-web
Copy link
Copy Markdown

@Teti-web Teti-web commented Mar 4, 2026

No description provided.

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

This requires a change to meet the project's requirements. Well done on setting up the promise logic correctly! The main issue is that firstPromise rejects with an Error object instead of the required string.

The task specifies that it should reject with the message 'First promise was rejected'. Please update your code to reject with the string directly, like reject('First promise was rejected').

Additionally, as a best practice, you should clean up your event listeners and timers using removeEventListener() and clearTimeout() once a promise is settled. This prevents memory leaks and is a great habit to build for future projects.


✨ 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 +12 to +22
const firstPromise = new Promise((resolve, reject) => {
document.addEventListener('click', (e) => {
if (e.button === 0) {
resolve('First promise was resolved');
}
});

setTimeout(() => {
reject(new Error('First promise was rejected'));
}, 3000);
});
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 is settled (either resolved on click or rejected by the timeout), the click event listener and the setTimeout timer are not cleaned up. This can lead to memory leaks. Consider storing the timer ID and the event handler function in variables so you can use clearTimeout() and document.removeEventListener() when the promise is done.

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 asks to reject with the message 'First promise was rejected'. By using new Error(), you're rejecting with an Error object instead of the specified string. It's better to stick to the requirement: reject('First promise was rejected').

Comment thread src/scripts/main.js
Comment on lines +24 to +32
const secondPromise = new Promise((resolve) => {
document.addEventListener('click', () => {
resolve('Second promise was resolved');
});

document.addEventListener('contextmenu', () => {
resolve('Second promise was resolved');
});
});
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 promise works, but there's a small improvement to be made. After the promise is resolved by either a left or right click, the event listeners for click and contextmenu remain active. It's a best practice to remove event listeners when they are no longer needed to prevent memory leaks. You could define the event handlers as named functions and then remove them right after calling resolve.

Comment thread src/scripts/main.js
Comment on lines +34 to +53
const thirdPromise = new Promise((resolve) => {
let leftClicked = false;
let rightClicked = false;

document.addEventListener('click', () => {
leftClicked = true;

if (rightClicked) {
resolve('Third promise was resolved');
}
});

document.addEventListener('contextmenu', () => {
rightClicked = true;

if (leftClicked) {
resolve('Third promise was resolved');
}
});
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similar to the other promises, the event listeners for click and contextmenu are not removed after the promise is resolved. Once both clicks have occurred and resolve() is called, these listeners are no longer necessary and should be cleaned up using removeEventListener to prevent memory leaks.

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

Good progress on the task, and the logic for the second and third promises is looking great! However, I'm requesting one change that was also mentioned in the last review. The firstPromise needs to reject with the raw string 'First promise was rejected', but it's currently rejecting with an Error object. This is a specific requirement for the task and is causing the tests to fail.

Please update reject(new Error('First promise was rejected')) to reject('First promise was rejected') in src/scripts/main.js. After that small fix, you should be all set!


✨ 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 timerId = 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 pointed out in the last review. The requirement is to reject with the string message 'First promise was rejected', not an Error object. Please change this to reject('First promise was rejected') to match the task description.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Expected the Promise rejection reason to be an Error.eslintprefer-promise-reject-errors

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.

Sorry, the pull request review was unsuccessful for the following reasons:

Warning

No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]

If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.

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

Excellent work on this task! I am approving your solution. You've done a fantastic job implementing all the promises and their corresponding success and error handlers. I'm particularly impressed with how you managed the event listeners, ensuring they were cleaned up correctly after the promises settled. The logic for resolving and rejecting each promise perfectly matches the requirements. This code is clean, efficient, and fully functional. Great job!


✨ 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