FAQ: JavaScript Promises - Constructing a Promise Object

This community-built FAQ covers the “Constructing a Promise Object” exercise from the lesson “JavaScript Promises”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Asynchronous JavaScript
Asynchronous JavaScript

FAQs on the exercise Constructing a Promise Object

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


You’ll be writing your code in the code-editor, but we won’t be running it until the final step. To check your code for a step, you can press the “Check Work” button.

We’re going to create a promise representing ordering sunglasses from an online store. First, create the function, myExecutor() . Later on, you’ll pass this function into the Promise constructor.

myExecutor() should:

  • Have two parameters: resolve and reject
  • Check if the sunglasses property on the inventory object has a value greater than zero
  • If it does, myExecutor() should invoke resolve() with the string 'Sunglasses order processed.'
  • If it does not, myExecutor() should invoke reject() with the string 'That item is sold out.'

The answer to part one above is as follows , but before we dive into the code below , i wanted to highlight the key aspects, that we are using the ES6 syntax , arrow functions, the 'new ’ keyword
for objects and the use of 'const ’ to declare variables .Ok now , the fun part .

const myExecutor = (resolve, reject) => {
    if (inventory.sunglasses > 0) {
        resolve('Sunglasses order processed.');
    } else {
        reject('That item is sold out.');

The explanation is very simple , we are creating a arrow function and then we are making use of if and else statements in to check for a certain condition in the object inventory and we do that by referencing the object and its properties inside like below , this is very important because we can not just reference the property directly of an object .JS doesn’t know that

if (inventory.sunglasses > 0) {
        resolve('Sunglasses order processed.');


Create a function, orderSunglasses() . This function should have no parameters. It should return a new promise constructed by passing your myExecutor() function into the Promise constructor.

const orderSunglasses = () => {
    return new Promise(myExecutor);

```This is pretty self explanatory 


Create a variable  `orderPromise`  assigned to the returned value of your  `orderSunglasses()` function.

const orderPromise = orderSunglasses();

This is even easier , hope this helps the students .

Why is the function orderSunglasses used, as opposed to simply creating a variable which is set equal to a new promise.

let order = new Promise(myExecutor);

Why does Step 1 of the exercise fail the check if you use a function declaration instead of an arrow function? Both should accomplish the same thing, and I would expect functionality to be more important than using a specific syntax option.


For me it just failed any way. I even copied the solution. Still didn’t seem to be correct.

1 Like

What does this mean? :

Promise { ‘That item is sold out.’ }
(node:680) UnhandledPromiseRejectionWarning: Un
handled promise rejection (rejection id: 1): Th
at item is sold out.
(node:680) DeprecationWarning: Unhandled promis
e rejections are deprecated. In the future, pro
mise rejections that are not handled will termi
nate the Node.js process with a non-zero exit c


I had the same question. So I googled, and found this StackOverflow discussion.

It seems we need .catch() to handle a promise rejection. We will learn it in the 7th lesson in this module.


Step 2 says:

Create a function, orderSunglasses(). This function should have no parameters.
It should return a new promise constructed by passing your myExecutor()
function into the Promise constructor.

Ok, so then why is this wrong?

function orderSunglasses(){
return new Promise(myExecutor);

Why can I only proceed to the next step if I write it like this?

const orderSunglasses = () => {
return new Promise(myExecutor);

Hello all
Why object this can t be used to acess sunglasses property ?
const myExecutor= (resolve,reject)=>{
resolve(‘Sunglasses order processed.’);
reject(‘That item is sold out.’);

I know this is months later, but I just got to this lesson, and am wondering if you got an answer to this question?