Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a handler that logs the resolved value of the promise.
Javascript
Promise.resolve('Hello').[1](value => console.log(value));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using catch instead of then to handle success.
Using finally which does not receive the resolved value.
Trying to call resolve on the promise instance.
✗ Incorrect
The then method is used to handle the resolved value of a promise.
2fill in blank
mediumComplete the code to chain a second then that doubles the number.
Javascript
Promise.resolve(5).then(num => num).[1](num => num * 2);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using catch instead of then for chaining.
Using finally which does not modify the value.
Trying to call resolve which is not a method on the promise instance.
✗ Incorrect
To chain operations on promises, use then again.
3fill in blank
hardFix the error in the code by completing the blank with the correct method to catch errors.
Javascript
Promise.reject('Error occurred').[1](error => console.log(error));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using then which only handles success.
Using finally which does not receive error arguments.
Trying to call resolve which is not a method on the promise instance.
✗ Incorrect
The catch method handles rejected promises (errors).
4fill in blank
hardFill both blanks to create a promise chain that adds 3 then multiplies by 2.
Javascript
Promise.resolve(4).[1](num => num + 3).[2](num => num * 2);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using catch in the middle of the chain which breaks the flow.
Using finally which does not transform the value.
Trying to call resolve which is not a method on the promise instance.
✗ Incorrect
Both steps use then to process the resolved value sequentially.
5fill in blank
hardFill all three blanks to chain promises that fetch data, parse JSON, and log the result.
Javascript
fetch('url').[1](response => response.[2]()).[3](data => console.log(data));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using catch instead of then for success handlers.
Trying to call json as a property instead of a method.
Missing parentheses after json.
✗ Incorrect
Use then to handle promises, json() to parse response, and another then to log data.