0
0
Javascriptprogramming~10 mins

Promise chaining in Javascript - Interactive Code Practice

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

Complete 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'
Athen
Bcatch
Cfinally
Dresolve
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.
2fill in blank
medium

Complete 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'
Aresolve
Bfinally
Ccatch
Dthen
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.
3fill in blank
hard

Fix 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'
Athen
Bfinally
Ccatch
Dresolve
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.
4fill in blank
hard

Fill 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'
Athen
Bcatch
Cfinally
Dresolve
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.
5fill in blank
hard

Fill 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'
Athen
Bjson
Dcatch
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.