0
0
Javascriptprogramming~10 mins

Creating promises in Javascript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new Promise that resolves with 'Done'.

Javascript
const promise = new Promise(([1]) => {
  resolve('Done');
});
Drag options to blanks, or click blank then click option'
Adone
Breject
Cresolve
Dcallback
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'reject' instead of 'resolve' when fulfilling the promise.
Using a parameter name that is not 'resolve' or 'reject'.
2fill in blank
medium

Complete the code to create a Promise that rejects with an error message.

Javascript
const promise = new Promise((resolve, [1]) => {
  [1]('Error occurred');
});
Drag options to blanks, or click blank then click option'
Areject
Bresolve
Cfail
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Calling 'resolve' instead of 'reject' to reject the promise.
Using incorrect parameter names.
3fill in blank
hard

Fix the error in the Promise executor function parameter to correctly create a Promise.

Javascript
const promise = new Promise([1] => {
  resolve('Success');
});
Drag options to blanks, or click blank then click option'
Aresolve
B()
C(callback)
D(resolve, reject)
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single parameter without parentheses.
Omitting the reject parameter.
4fill in blank
hard

Fill both blanks to create a Promise that resolves after 1 second with 'Done'.

Javascript
const promise = new Promise(([1], [2]) => {
  setTimeout(() => [1]('Done'), 1000);
});
Drag options to blanks, or click blank then click option'
Aresolve
Breject
Ccallback
Ddone
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names.
Calling reject instead of resolve inside setTimeout.
5fill in blank
hard

Fill all three blanks to create a Promise that resolves with the uppercase version of input after 500ms.

Javascript
function toUpperAsync(str) {
  return new Promise(([1], [2]) => {
    setTimeout(() => [1](str[3]), 500);
  });
}
Drag options to blanks, or click blank then click option'
Aresolve
Breject
C.toUpperCase()
D.toLowerCase()
Attempts:
3 left
💡 Hint
Common Mistakes
Using .toLowerCase() instead of .toUpperCase().
Calling reject instead of resolve.
Missing parentheses around parameters.