Https://www.codecademy.com/paths/web-development/tracks/webdev-intermediate-javascript/modules/javascript-promises/lessons/promises/exercises/promise-all


#1

Hello!
The last exercise (N. 10) on Promises, Mod. 8, is throwing an error even after the given solution:

//importing app.js file 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) => {
console.log(rejectionReason);
};

// Write your code below:
//importing app.js file from library.js
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)
.catch(onReject);

//exporting library.js file to app.js:

const checkAvailability = (itemName, distributorName) => {
console.log(Checking availability of ${itemName} at ${distributorName}...);
return new Promise((resolve, reject) => {
setTimeout(() => {
if (restockSuccess()) {
console.log(${itemName} are in stock at ${distributorName})
resolve(itemName);
} else {
reject(Error: ${itemName} is unavailable from ${distributorName} at this time.);
}
}, 1000);
});
};

module.exports = { checkAvailability };

// This is a function that returns true 80% of the time
// We’re using it to simulate a request to the distributor being successful this often
function restockSuccess() {
return (Math.random() > .2);
}