Having trouble with promises

Hi! I’m having a little bit of trouble with the Promise.all code.

The exercise is https://www.codecademy.com/courses/introduction-to-javascript/lessons/promises/exercises/promise-all

Here is my code:

const {checkAvailability} = require('./library.js');

const onFulfill = (itemsArray) => {
  console.log(`Items checked: ${itemsArray}`);
  console.log(`Every item was available from the distributor. Placing order now.`);

const onReject = (rejectionReason) => {

// Write your code below:

const checkSunglasses = checkAvailability('sunglasses', 'Favorite Supply Co.')

const checkPants = checkAvailability('pants', 'Favorite Supply Co.')

const checkBags = checkAvailability('bags', 'Favorite Supply Co.')

Promise.all([checkSunglasses(), checkPants(), checkBags()])
.then((onFulfill) => {

I keep getting the error message “Did you pass the onFulfill function into .then() as the success handler? It should be the only argument to .then() . Make sure to pass it in uninvoked.”

I’d be grateful for any help on this.

Am I getting the Promise.all syntax wrong?

Think what’s happening is when you create your checkAvailability consts as follows…

const checkBags = checkAvailability('bags', 'Favorite Supply Co.')

… this means that any use of checkBags is going to call checkAvailability with those arguments.

So you would call checkAvailability with those arguments, by doing:


and not:


checkBags isn’t a function; it’s a call to a function.

Hey @antonjw! Interesting, I implemented that, but I still get the exact same error…

It might be because your onFulfill function need a parameter ?

Now in your then() you are calling for a variable that does not exist. onFulfill is a function after all.
I do not know what is expected in onFulfill tho. It is not clear to me what itemsArray needs to be.

Also, here is the hint:

Since Promise.all() returns a single promise, we’ll chain this .then() directly onto it similarly to this:

Promise.all([firstPromise, secondPromise, thirdPromise])
.then((resolvedValue) => {console.log(resolvedValue)})

Yeah its the learning platform itself not letting you progress. It doesn’t like how you’re doing your call to onFulfill.

Consider what you are doing in your call to onFulfill… why are you console.logging after the call?

You’re console.loggoing the function itself, not a string or even the result of calling the function.

Doesn’t the call to onFulfill by itself do everything you need it to do?

1 Like

So I finally gave up and got the solution… (sorry @antonjw, you were right, I just didn’t read it before I pressed get solution), and here is the solution I got:

Promise.all([checkSunglasses, checkPants, checkBags])

So yeah, you were right Antonjw

1 Like