-
Notifications
You must be signed in to change notification settings - Fork 1.5k
added solution #1561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
added solution #1561
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,50 @@ | ||
| 'use strict'; | ||
|
|
||
| // write your code here | ||
| const logo = document.querySelector('.logo'); | ||
|
|
||
| function createPromise1() { | ||
| return new Promise((resolve, reject) => { | ||
| resolve('Promise was resolved!'); | ||
| }); | ||
| } | ||
|
|
||
| logo.addEventListener('click', async () => { | ||
| try { | ||
| const promise1 = await createPromise1(); | ||
|
Comment on lines
+11
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The click handler currently creates and resolves the promise via |
||
|
|
||
| const division = document.createElement('div'); | ||
|
|
||
| division.classList.add('message'); | ||
| division.textContent = promise1; | ||
| document.body.appendChild(division); | ||
|
Comment on lines
+15
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The success path for |
||
| } catch (error) { | ||
| const division = document.createElement('div'); | ||
|
|
||
| division.classList.add('message', | ||
| 'error-message'); | ||
| division.textContent = error.message; | ||
| document.body.appendChild(division); | ||
| } | ||
|
Comment on lines
+20
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error handling for |
||
| }); | ||
|
|
||
| const promise2 = new Promise((resolve, reject) => { | ||
| setTimeout(() => { | ||
| reject(new Error('Promise was rejected!')); | ||
| }, 3000); | ||
| }); | ||
|
|
||
| promise2.then((result) => { | ||
| const division = document.createElement('div'); | ||
|
|
||
| division.classList.add('message'); | ||
| division.textContent = result; | ||
| document.body.appendChild(division); | ||
|
Comment on lines
+36
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the |
||
| }); | ||
|
|
||
| promise2.catch((error) => { | ||
| const division = document.createElement('div'); | ||
|
|
||
| division.classList.add('message', 'error-message'); | ||
| division.textContent = error.message; | ||
|
Comment on lines
+44
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the |
||
| document.body.appendChild(division); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
promise1is required to be a top-level named promise (const promise1 = new Promise(...)) with its own.thenand.catchhandlers. DefiningcreatePromise1()that creates and resolves the promise internally meanspromise1is not a named top-level promise as specified.