Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Chained Then

Asynchronous JavaScriptmedium

Course · Section 16: Asynchronous JavaScript: Promises, Async/Await, and AJAX · Lecture 263: Promises and the Fetch API

Implement `chainAdd(n)` returning a promise that resolves `n`, adds 1, then doubles the result, using `.then` chaining.

Sample tests

Input: chainAdd(3)
Output: 8
Input: chainAdd(0)
Output: 2

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Returning before the chain resolves; return the chain itself.

Learning resources

  • MDN: Promise
Visualize this concept: The Event Loop →
Approach & explanation (try first)

Each .then transforms the resolved value, composing add-one then double.

Loading...
⌘/Ctrl + Enter

Run your code to see results.