Challenge - 5 Problems
Promise Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does Promise.race output?
Consider the following code snippet using
Promise.race. What will be logged to the console?Node.js
const p1 = new Promise(resolve => setTimeout(() => resolve('First'), 300)); const p2 = new Promise(resolve => setTimeout(() => resolve('Second'), 100)); Promise.race([p1, p2]).then(result => console.log(result));
Attempts:
2 left
💡 Hint
Think about which promise resolves first based on the timeout durations.
✗ Incorrect
Promise.race returns the result of the first promise that settles (resolves or rejects). Since p2 resolves after 100ms and p1 after 300ms, the output is "Second".
❓ state_output
intermediate2:00remaining
What is the output of Promise.allSettled?
Given the following promises, what will
Promise.allSettled return?Node.js
const p1 = Promise.resolve('Success'); const p2 = Promise.reject('Error'); Promise.allSettled([p1, p2]).then(results => console.log(results));
Attempts:
2 left
💡 Hint
Remember that
allSettled waits for all promises and reports their status.✗ Incorrect
Promise.allSettled returns an array describing each promise's outcome. The first promise fulfilled with value "Success" and the second rejected with reason "Error".
📝 Syntax
advanced2:00remaining
Which option causes a syntax error with Promise.race?
Identify which code snippet will cause a syntax error when using
Promise.race.Attempts:
2 left
💡 Hint
Check the expected argument type for Promise.race.
✗ Incorrect
Promise.race expects a single iterable (like an array) of promises. Option A passes two arguments instead of one array, causing a syntax error.
🔧 Debug
advanced2:00remaining
Why does this Promise.allSettled code not log results?
This code does not log anything. What is the reason?
Node.js
const p1 = Promise.resolve('Done'); const p2 = Promise.reject('Fail'); Promise.allSettled([p1, p2]);
Attempts:
2 left
💡 Hint
Promises are lazy until you handle their result.
✗ Incorrect
Without .then() or await, the promise settles but no code runs to log the results.
🧠 Conceptual
expert2:00remaining
Which statement about Promise.race and Promise.allSettled is true?
Select the only true statement about
Promise.race and Promise.allSettled:Attempts:
2 left
💡 Hint
Think about how each method handles multiple promises and their timing.
✗ Incorrect
Promise.race settles as soon as any promise settles (resolves or rejects). Promise.allSettled waits for all promises to settle and never rejects.