From b6832a3b687f565dbd70db28e2f8f2e1c5e58a58 Mon Sep 17 00:00:00 2001 From: Oleksandra Zarubina Date: Wed, 3 Jun 2026 15:45:10 +0300 Subject: [PATCH 1/2] add task solution --- README.md | 2 +- src/scripts/main.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1395a36c..1f229c15 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Create 2 promises `promise1` and `promise2`. ## Instructions 1. Replace `` with your Github username in the link - - [DEMO LINK](https://.github.io/js_promise_basic_DOM/) + - [DEMO LINK](https://zarubina20.github.io/js_promise_basic_DOM/) 2. Follow [this instructions](https://mate-academy.github.io/layout_task-guideline/) - Run `npm run test` command to test your code; - Run `npm run test:only -- -n` to run fast test ignoring linter; diff --git a/src/scripts/main.js b/src/scripts/main.js index c6e3f878..c1facbaf 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,32 @@ 'use strict'; // write your code here +const promise1 = new Promise((resolve) => { + document + .querySelector('.logo') + .addEventListener('click', () => resolve(), { once: true }); +}); + +promise1.then(() => { + const div = document.createElement('div'); + + div.className = 'message'; + + div.textContent = 'Promise was resolved!'; + + document.body.appendChild(div); +}); + +const promise2 = new Promise((resolve, reject) => { + setTimeout(() => reject(new Error('Timed out')), 3000); +}); + +promise2.catch(() => { + const div = document.createElement('div'); + + div.className = 'message error-message'; + + div.textContent = 'Promise was rejected!'; + + document.body.appendChild(div); +}); From 8f745abe6f829aa357edb5ded4500170ecdd1dca Mon Sep 17 00:00:00 2001 From: Oleksandra Zarubina Date: Wed, 3 Jun 2026 16:00:32 +0300 Subject: [PATCH 2/2] Fixed task comments --- src/scripts/main.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/scripts/main.js b/src/scripts/main.js index c1facbaf..2f6de9d7 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -17,10 +17,30 @@ promise1.then(() => { document.body.appendChild(div); }); +promise1.catch(() => { + const div = document.createElement('div'); + + div.className = 'message error-message'; + + div.textContent = 'Promise was rejected!'; + + document.body.appendChild(div); +}); + const promise2 = new Promise((resolve, reject) => { setTimeout(() => reject(new Error('Timed out')), 3000); }); +promise2.then(() => { + const div = document.createElement('div'); + + div.className = 'message'; + + div.textContent = 'Promise was resolved!'; + + document.body.appendChild(div); +}); + promise2.catch(() => { const div = document.createElement('div');