Skip to content

Add task solution#1357

Open
OleksiiHolodok wants to merge 3 commits intomate-academy:masterfrom
OleksiiHolodok:develop
Open

Add task solution#1357
OleksiiHolodok wants to merge 3 commits intomate-academy:masterfrom
OleksiiHolodok:develop

Conversation

@OleksiiHolodok
Copy link
Copy Markdown

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

I am requesting changes because a few core behavioral requirements of the promises are not yet met, which will likely cause tests to fail.

Critical issues to fix:

  • For firstPromise in src/scripts/main.js, the rejection currently uses an Error object. The requirement is that it rejects with the exact string message "First promise was rejected", so you should call reject('First promise was rejected') (or ensure the catch receives that exact string).
  • For secondPromise, the mousedown handler currently resolves on any mouse button. The requirement is to resolve only for left (button 0) or right (button 2) clicks, so add a guard like if (ev.button === 0 || ev.button === 2) { resolve(...) } before resolving.
  • The task requires both success and error handlers for each promise. secondPromise and thirdPromise currently only have .then success handlers; add .catch((message) => showNotification(message, 'error')) to each so that errors are handled in the same way as for the first promise.

Once you adjust the rejection value, restrict secondPromise to left/right clicks, and add the missing .catch handlers, your implementation should align well with the specified behavior. You’ve already done a good job setting up the three promises and the notification helper; these targeted fixes will complete the task.


✨ 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

setTimeout(() => {
if (!resolved) {
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 promise is rejected with an Error object here. The requirement states the promise must be rejected with the message First promise was rejected. Reject with the string directly (for example: reject('First promise was rejected')) so the catch handler receives the exact message.

Comment thread src/scripts/main.js Outdated
Comment on lines +34 to +36
const onMouseDown = (ev) => {
resolve('Second promise was resolved');
document.removeEventListener('mousedown', onMouseDown);
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 onMouseDown handler resolves secondPromise for every mouse button (including middle click). The requirement is to resolve only on left (0) or right (2) clicks. Add a check such as if (ev.button === 0 || ev.button === 2) { resolve(...) } before resolving.

Comment thread src/scripts/main.js Outdated
.then((message) => showNotification(message, 'success'))
.catch((message) => showNotification(message, 'error'));

secondPromise.then((message) => showNotification(message, 'success'));
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 adding both success and error handlers for each promise. secondPromise currently only has a success handler attached. Add a .catch((message) => showNotification(message, 'error')) so it has both success and error handlers as required.

Comment thread src/scripts/main.js Outdated

secondPromise.then((message) => showNotification(message, 'success'));

thirdPromise.then((message) => showNotification(message, 'success'));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same issue for thirdPromise: only a success handler is attached. Add a .catch((message) => showNotification(message, 'error')) to ensure both success and error handlers exist for this promise as the requirements ask.

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 a core requirement for secondPromise is not yet met, which is considered a blocking issue. Specifically, in src/scripts/main.js, your handlers for secondPromise (onLeftClick / onRightClick and their listeners) do not accept the mouse event and do not check ev.button, so the promise can resolve on activations other than left (0) or right (2) button clicks, violating the checklist requirements [CHECKLIST ITEM #10] and [CHECKLIST ITEM #11]. To fix this, update the event handlers used by secondPromise (e.g., switch to mousedown or adjust existing handlers) so they receive the event parameter and only call resolve(...) when ev.button === 0 || ev.button === 2. For example, something like:

  • element.addEventListener('mousedown', (ev) => { if (ev.button === 0 || ev.button === 2) resolve(...); });

would satisfy the requirement as long as you wire it correctly into your current structure. Aside from this button-guard issue, the rest of your promise logic (creation of three promises, resolve/reject flows, and notification handling) looks aligned with the task, so once you add this guard your solution should fully comply. You're very close—tightening this event handling will bring your implementation in line with the spec.


✨ 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
Comment on lines +42 to +46
const onLeftClick = () => {
leftClick = true;
resolve(successMessage);
clear(onLeftClick, onRightClick);
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

onLeftClick for secondPromise doesn't accept an event object or check ev.button. Checklist item #11 requires a guard so resolution happens only when ev.button === 0 || ev.button === 2. Update this handler (or switch to mousedown) to receive the event and only call resolve(...) when that condition is true.

Comment thread src/scripts/main.js Outdated
Comment on lines +48 to +55
const onRightClick = () => {
rightClick = true;
resolve(successMessage);
clear(onLeftClick, onRightClick);
};

document.addEventListener('click', onLeftClick);
document.addEventListener('contextmenu', onRightClick);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

onRightClick and the listeners for secondPromise currently call resolve(...) unconditionally and rely on click/contextmenu. This can allow non-left/right activations to resolve the promise. Use an event handler that checks ev.button === 0 || ev.button === 2 (or use mousedown and the same guard) before calling resolve(...) to satisfy checklist items #10 and #11.

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 continue progressing while you learn from this task. You did a solid job implementing the three promises, wiring up the click handlers, and using the notification system via <div data-qa="notification"> with appropriate success and error classes. One important issue remains in src/scripts/main.js: in thirdPromise, the right-click handler currently checks ev.buttons === 2 instead of ev.button === 2, which can cause right-clicks not to be detected correctly and prevents the promise from resolving as intended (the requirement is to check ev.button for 0 and 2). To fix this, update the right-click handler’s condition to if (ev.button === 2) { ... } so that the third promise reliably recognizes a right mouse button click. As a minor improvement, consider keeping any left/right click tracking variables local to thirdPromise so different promises don’t accidentally share state. Overall, your structure and use of promises and handlers show good understanding—this is a small but important detail to adjust next time.


✨ 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
};

const onRightClick = (ev) => {
if (ev.buttons === 2) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In thirdPromise the right-click handler checks ev.buttons === 2. The requirement (and the checks used elsewhere in the file) expects ev.button === 2 so the handler only resolves on a right mouse button activation. Change this to if (ev.button === 2) { ... } so the third promise reliably detects right-clicks.

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