You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constinventory={sunglasses: 1900,pants: 1088,bags: 1344};constcheckInventory=(order)=>{returnnewPromise((resolve,reject)=>{setTimeout(()=>{letinStock=order.every(item=>inventory[item[0]]>=item[1]);if(inStock){resolve(`Thank you. Your order was successful.`);}else{reject(`We're sorry. Your order could not be completed because some items are sold out.`);}},1000);})};module.exports={ checkInventory };
app.js
const{checkInventory}=require('./library.js');constorder=[['sunglasses',1],['bags',2]];// Write your code below:consthandleSuccess=(resolvedValue)=>{console.log(resolvedValue);};consthandleFailure=(rejectReason)=>{console.log(rejectReason);};checkInventory(order).then(handleSuccess,handleFailure);
This is one of Codecademy's practice code for async javascript practice!
The goal for this exercise is to create a calculator that does the following:
add, subtract, get the sum, multiply, get the power, and find the factorial
In order to do this please fill out each function with your solution. Make sure to return the value so you can test it in Jest! To see the expected value
take a look at the spec file that houses the Jest test cases.
constadd=function(a,b){returna+b;};constsubtract=function(a,b){returna-b;};constsum=function(array){returnarray.reduce((total,current)=>total+current,0);};constmultiply=function(...args){letproduct=1;for(leti=0;i<args.length;i++){product*=args[i];}returnproduct;};constpower=function(a,b){returnMath.pow(a,b);};constfactorial=function(n){if(n===0)return1;letproduct=1;for(leti=n;i>0;i--){product*=i;}returnproduct;};// This is another implementation of Factorial that uses recursion// THANKS to @ThirtyThreeB!constrecursiveFactorial=function(n){if(n===0){return1;}returnn*recursiveFactorial(n-1);};