Challenge - 5 Problems
Async Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Promise chain?
Consider the following Node.js code using Promises. What will be logged to the console?
Node.js
Promise.resolve(5) .then(x => x * 2) .then(x => { throw new Error('Fail'); }) .catch(() => 10) .then(x => x + 1) .then(console.log);
Attempts:
2 left
💡 Hint
Remember that catch returns a resolved Promise with the value it returns.
✗ Incorrect
The chain starts with 5, doubles to 10, then throws an error. The catch handles the error and returns 10. Then 1 is added, resulting in 11, which is logged.
❓ component_behavior
intermediate2:00remaining
Which option correctly returns a Promise that resolves after 1 second?
You want to create a function that returns a Promise resolving with 'done' after 1 second. Which code does this correctly?
Attempts:
2 left
💡 Hint
Remember that setTimeout returns a timer ID, not a Promise.
✗ Incorrect
Option C correctly creates a Promise and resolves it after 1 second using setTimeout. Other options either don't return a Promise or resolve immediately.
🔧 Debug
advanced2:00remaining
Why does this Promise chain never log anything?
Look at this code snippet. Why does it never log 'Finished'?
Node.js
Promise.resolve()
.then(() => { throw 'Error happened'; })
.then(() => console.log('Finished'));Attempts:
2 left
💡 Hint
Think about what happens when a Promise rejects and no catch is present.
✗ Incorrect
The thrown error causes the Promise to reject. Without a catch, the next then is skipped, so 'Finished' is never logged.
📝 Syntax
advanced2:00remaining
Which option correctly chains Promises to fetch data and process it?
Given fetchData() returns a Promise resolving to data, which code correctly fetches and logs the processed data?
Node.js
function process(data) { return data.length; }Attempts:
2 left
💡 Hint
Remember to pass functions, not call them immediately in then.
✗ Incorrect
Options A and B correctly pass functions to then. Option C calls process immediately, D does not return from then.
🧠 Conceptual
expert2:00remaining
What is the behavior of Promise.all with mixed resolved and rejected Promises?
Given these Promises: p1 resolves, p2 rejects, p3 resolves. What does Promise.all([p1, p2, p3]) do?
Attempts:
2 left
💡 Hint
Promise.all rejects as soon as any Promise rejects.
✗ Incorrect
Promise.all rejects immediately when any Promise rejects, with that rejection reason.