Add task solution#1357
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
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
firstPromiseinsrc/scripts/main.js, the rejection currently uses anErrorobject. The requirement is that it rejects with the exact string message"First promise was rejected", so you should callreject('First promise was rejected')(or ensure the catch receives that exact string). - For
secondPromise, themousedownhandler currently resolves on any mouse button. The requirement is to resolve only for left (button0) or right (button2) clicks, so add a guard likeif (ev.button === 0 || ev.button === 2) { resolve(...) }before resolving. - The task requires both success and error handlers for each promise.
secondPromiseandthirdPromisecurrently only have.thensuccess 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
|
|
||
| setTimeout(() => { | ||
| if (!resolved) { | ||
| reject(new Error('First promise was rejected')); |
There was a problem hiding this comment.
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.
| const onMouseDown = (ev) => { | ||
| resolve('Second promise was resolved'); | ||
| document.removeEventListener('mousedown', onMouseDown); |
There was a problem hiding this comment.
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.
| .then((message) => showNotification(message, 'success')) | ||
| .catch((message) => showNotification(message, 'error')); | ||
|
|
||
| secondPromise.then((message) => showNotification(message, 'success')); |
There was a problem hiding this comment.
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.
|
|
||
| secondPromise.then((message) => showNotification(message, 'success')); | ||
|
|
||
| thirdPromise.then((message) => showNotification(message, 'success')); |
There was a problem hiding this comment.
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.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
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
| const onLeftClick = () => { | ||
| leftClick = true; | ||
| resolve(successMessage); | ||
| clear(onLeftClick, onRightClick); | ||
| }; |
There was a problem hiding this comment.
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.
| const onRightClick = () => { | ||
| rightClick = true; | ||
| resolve(successMessage); | ||
| clear(onLeftClick, onRightClick); | ||
| }; | ||
|
|
||
| document.addEventListener('click', onLeftClick); | ||
| document.addEventListener('contextmenu', onRightClick); |
There was a problem hiding this comment.
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.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
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
| }; | ||
|
|
||
| const onRightClick = (ev) => { | ||
| if (ev.buttons === 2) { |
There was a problem hiding this comment.
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.
No description provided.