Promise function returns only success

hi!
There is lack iof information on the exercise in this section:
https://www.codecademy.com/courses/introduction-to-javascript/lessons/promises/exercises/onfulfilled-onrejected

Even if the values of the items in the variable “order” are both 0, you always get the resolve value. See the screenshot:

I know it has to do with the variable “let inStock” in library.js:

let inStock = order.every(item => inventory[item[0]] >= item[1]);

I do not understand the logic. I don´t get why it stil returns a resolvedValue, altough I set both values to 0.

Can someone explain me why?

Thx,
Alejandro

Hi Alejandro,
I can see that you set your order to 0. And since they probably don’t have a problem delivering zero bags and sunglasses, whatever they have in stock, you get a resolved value:

let inStock = order.every(item => inventory[item[0]] >= item[1]); // --> true

The method order.every() iterates through each item in the array you passed in: order. See MDN docs
and returns a boolean after checking the condition you provided. Here >=.

For the first iteration it would be this:
inventory[item[0]] equals inventory.sunglasses from the stock (const inventory)
item[1] equals order[0][1] (sunglasses value) from the order.

Try to set the order to a higher value:

const order = [['sunglasses', 100], ['bags', 200]];

than the inventory:

const inventory = {
  sunglasses: 19,
  pants: 1088,
  bags: 13
};

And see which result you get then.

1 Like

If only life would be like your promise function :frowning: :stuck_out_tongue:

Thank you @mirja_t .

1 Like