diff --git a/README.md b/README.md index 1395a36c..b353e910 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://Rostyslav452.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..59ef7d46 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,28 @@ 'use strict'; -// write your code here +const promise1 = new Promise((resolve, reject) => { + document.querySelector('.logo').addEventListener('click', () => { + resolve(); + }); +}); + +const promise2 = new Promise((resolve, reject) => { + setTimeout(() => { + reject(new Error()); + }, 3000); +}); + +const fulfilled = () => + document.body.insertAdjacentHTML( + 'afterbegin', + '
Promise was resolved!
', + ); +const rejected = () => + document.body.insertAdjacentHTML( + 'afterbegin', + '
Promise was rejected!
', + ); + +promise1.then(fulfilled, rejected); + +promise2.then(fulfilled, rejected);