Challenge - 5 Problems
Promise Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Promise chain?
Consider the following Node.js code using Promise chaining. What will be logged to the console?
Node.js
Promise.resolve(5) .then(x => x * 2) .then(x => { console.log(x); return x + 1; }) .then(x => console.log(x));
Attempts:
2 left
💡 Hint
Remember each then returns a new Promise with the returned value.
✗ Incorrect
The first then doubles 5 to 10. The second then logs 10 and returns 11. The third then logs 11.
📝 Syntax
intermediate2:00remaining
Which option causes a syntax error in Promise chaining?
Identify which code snippet will cause a syntax error when chaining Promises in Node.js.
Attempts:
2 left
💡 Hint
Look carefully at parentheses and braces.
✗ Incorrect
Option B is missing a closing parenthesis at the end, causing a syntax error.
🔧 Debug
advanced2:00remaining
Why does this Promise chain not log the expected value?
Given the code below, why does the console.log output 'undefined' instead of the expected number?
Node.js
Promise.resolve(3) .then(x => { x * 3; }) .then(x => console.log(x));
Attempts:
2 left
💡 Hint
Check if the first then returns a value explicitly.
✗ Incorrect
Without a return statement, the first then returns undefined, so the next then receives undefined.
❓ state_output
advanced2:00remaining
What is the final value of 'result' after this Promise chain?
Analyze the code and determine the value of the variable 'result' after the Promise chain completes.
Node.js
let result = 0; Promise.resolve(2) .then(x => x + 3) .then(x => { result = x * 2; }) .then(() => console.log('Done'));
Attempts:
2 left
💡 Hint
Follow the values through each then and how 'result' is assigned.
✗ Incorrect
2 + 3 = 5, then result = 5 * 2 = 10.
🧠 Conceptual
expert3:00remaining
Which option correctly handles errors in a Promise chain?
Choose the code snippet that properly catches errors occurring in any step of the Promise chain.
Attempts:
2 left
💡 Hint
Errors thrown in any then should be caught by catch at the end.
✗ Incorrect
Option C throws an error in a then, which is caught by the final catch. Option C also catches but does not continue chaining after error. Option C uses second then argument which only catches errors in previous Promise, not in the chain. Option C's catch is before the error throw, so it won't catch it.