Skip to content

feat: add promise solution#1554

Open
m-berezovskyy wants to merge 2 commits into
mate-academy:masterfrom
m-berezovskyy:develop
Open

feat: add promise solution#1554
m-berezovskyy wants to merge 2 commits into
mate-academy:masterfrom
m-berezovskyy:develop

Conversation

@m-berezovskyy

Copy link
Copy Markdown

No description provided.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

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 one core requirement from the task description is not fully met yet: both promises must have both success and error handlers. Right now, promise1 only has a success handler (then) but no error handler, and promise2 only has an error handler (catch) but no success handler. This means the behavior specified in the task (showing both the resolved and rejected messages for each promise) is incomplete and could cause tests that expect all handlers to fail.

To fix this:

  • Add an error handler for promise1 (either promise1.catch(...) or a second argument to then) that appends <div class="message error-message">Promise was rejected!</div> to document.body when promise1 is rejected.
  • Add a success handler for promise2 (promise2.then(...)) that appends <div class="message">Promise was resolved!</div> to document.body when promise2 resolves.
    You’ve already implemented the promises themselves and the existing handlers correctly, so once you add these two missing handlers, your solution should fully satisfy the task requirements. Keep going—you’re very close to a complete and correct implementation.

✨ 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 +11 to +17
promise1.then(() => {
const messageDiv = document.createElement('div');

messageDiv.classList.add('message');
messageDiv.textContent = 'Promise was resolved!';
document.body.append(messageDiv);
});

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 both success and error handlers for each promise. promise1 currently has only a success handler; you should also add a catch (or second argument to then) that appends the error <div class="message error-message">Promise was rejected!</div> to the body.

Comment thread src/scripts/main.js
Comment on lines +19 to +31
const promise2 = new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error('Timeout!'));
}, 3000);
});

promise2.catch(() => {
const errorDiv = document.createElement('div');

errorDiv.classList.add('message', 'error-message');
errorDiv.textContent = 'Promise was rejected!';
document.body.append(errorDiv);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similarly, promise2 only has an error handler. The requirements say to add success handlers for both promises, so you should also attach a then to promise2 that appends the success <div class="message">Promise was resolved!</div> to the body.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

Your solution is approved because it correctly implements all of the required promise behavior and DOM updates. You created two promises, promise1 and promise2, with promise1 resolving on .logo click and promise2 rejecting after 3 seconds, matching the task specification. Both promises have then and catch handlers, and each handler appends the correct message elements to document.body with the appropriate classes for success (<div class="message">Promise was resolved!</div>) and error (<div class="message error-message">Promise was rejected!</div>). This means the core functional requirements and expected test behavior should be fully satisfied.

The only remaining items to double-check are non-blocking: ensure the README demo link has <your_account> replaced with your actual account name, and make sure you have run the required npm run test and npm run test:only commands locally as requested in the task instructions. Functionally, though, your JavaScript implementation looks clear, idiomatic, and aligned with the exercise goals. Nicely done on wiring up the promises and handlers in a clean, straightforward way.


✨ 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