Promises - accessing the store's stock

Hi there!

I am new and I hope this question is not too silly.

I´m stuck on this exercise trying to implement something on my own: https://www.codecademy.com/paths/web-development/tracks/webdev-intermediate-javascript/modules/javascript-promises/lessons/promises/exercises/chaining-promises

I am trying to add a new functionality inside “checkInventory” (just checking if I am capable of doing so) and I don´t know why it is not working.

I am trying to rest the quantity of the order´s products to the store stock with this code:

const checkInventory = (order) => {
  return new Promise ((resolve, reject) => {
   setTimeout(()=> {  
   const itemsArr = order.items;
   let inStock = itemsArr.every(item => store[item[0]].inventory >= item[1]
);
   
   if (inStock){
     let total = 0;   
     itemsArr.forEach(item => {
       total += item[1] * store[item[0]].cost
     });
	/* THIS IS MY CODE

  	itemsArr.forEach ( item => { store[item[0]].inventory -= item[1]
     console.log(store[item[0]].inventory);
     console.log(item[1])
});
*/

[...]

I know I am correctly accessing the property value because when I print it, it works. It prints 816 sunglasses and 16 bags. But the store variable stays the same. I tried changing it from “const” to “let” but it doesn´t seem to be the problem.

Any thoughts?

Hello, @vidmario.

Welcome to the forum.

When I run your code, store is changed. It may be the location of your console.log(store) statement that is leading you to believe it remains unchanged. I added a console.log(store) statement in the shipOrder() function right before the return statement, and I see the updated values.