1.6 KiB
1.6 KiB
id, title, challengeType, forumTopicId
id | title | challengeType | forumTopicId |
---|---|---|---|
5cdafbb0291309899753167f | Create a JavaScript Promise | 1 | 301197 |
Description
Promise
is a constructor function, so you need to use the new
keyword to create one. It takes a function, as its argument, with two parameters - resolve
and reject
. These are methods used to determine the outcome of the promise. The syntax looks like this:
const myPromise = new Promise((resolve, reject) => {
});
Instructions
makeServerRequest
. Pass in a function with resolve
and reject
parameters to the constructor.
Tests
tests:
- text: You should assign a promise to a declared variable named <code>makeServerRequest</code>.
testString: assert(makeServerRequest instanceof Promise);
- text: Your promise should receive a function with <code>resolve</code> and <code>reject</code> as parameters.
testString: assert(code.match(/Promise\(\s*(function\s*\(\s*resolve\s*,\s*reject\s*\)\s*{|\(\s*resolve\s*,\s*reject\s*\)\s*=>\s*{)[^}]*}/g));
Challenge Seed
Solution
const makeServerRequest = new Promise((resolve, reject) => {
});