Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a resolved promise.
Node.js
const promise = Promise.[1]('Done');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using reject instead of resolve
Using Promise.all or Promise.race incorrectly
✗ Incorrect
The Promise.resolve() method creates a promise that is resolved with the given value.
2fill in blank
mediumComplete the code to add a handler for the resolved value.
Node.js
promise.[1](result => console.log(result)); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using catch instead of then
Using finally which runs regardless of outcome
✗ Incorrect
The then method adds a callback for when the promise is fulfilled.
3fill in blank
hardFix the error in chaining a promise to handle rejection.
Node.js
promise.then(result => console.log(result)).[1](error => console.error(error)); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using then instead of catch for errors
Using finally which does not handle errors
✗ Incorrect
The catch method handles promise rejections or errors.
4fill in blank
hardFill both blanks to chain two promises where the second depends on the first.
Node.js
fetchData().[1](data => processData(data)).[2](result => console.log(result));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using catch or finally in place of then in the chain
Using resolve which is not a method on promises
✗ Incorrect
Use then to chain promises and handle their results sequentially.
5fill in blank
hardFill all three blanks to create a promise chain with success, error, and cleanup handlers.
Node.js
getUser().[1](user => getProfile(user.id)).[2](error => console.error(error)).[3](() => console.log('Done'));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up catch and finally
Using resolve which is not a chain method
✗ Incorrect
The chain uses then for success, catch for errors, and finally for cleanup.