Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work on this task! Your solution correctly implements all the requirements: promise1 resolves on a click, and promise2 rejects after a timeout, with both handlers correctly manipulating the DOM.
I am approving your submission. As a point for future improvement, consider how you might reduce code duplication. The logic for creating and appending the message div is repeated in your success and error handlers. You could extract this logic into separate functions to make your code cleaner and more maintainable, following the DRY (Don't Repeat Yourself) principle.
Keep up the great work!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| promise1 | ||
| .then(() => { | ||
| const div = document.createElement('div'); | ||
|
|
||
| div.classList.add('message'); | ||
| div.textContent = 'Promise was resolved!'; | ||
| body.append(div); | ||
| }) | ||
| .catch(() => { | ||
| const div = document.createElement('div'); | ||
|
|
||
| div.classList.add('message', 'error-message'); | ||
| div.textContent = 'Promise was rejected!'; | ||
| body.append(div); | ||
| }); | ||
|
|
||
| promise2 | ||
| .then(() => { | ||
| const div = document.createElement('div'); | ||
|
|
||
| div.classList.add('message'); | ||
| div.textContent = 'Promise was resolved!'; | ||
| body.append(div); | ||
| }) | ||
| .catch(() => { | ||
| const div = document.createElement('div'); | ||
|
|
||
| div.classList.add('message', 'error-message'); | ||
| div.textContent = 'Promise was rejected!'; | ||
| body.append(div); | ||
| }); |
There was a problem hiding this comment.
The success and error handling logic is repeated for both promise1 and promise2. To make the code cleaner and more maintainable, consider creating two separate functions: one to handle successful promise resolution and one for rejection. You can then pass these functions as arguments to .then() and .catch() for both promises, avoiding code duplication.
No description provided.