Home

Calculator with promises

 
let e=5;const o=(e=1e3)=>new Promise((o,n)=>{isNaN(e)?n(new Error("Delay only except milliseconds")):setTimeout(()=>o(`waited for ${e} ms`),e)});console.log("x = "+e),console.warn("Give me two seconds, first empty my coffee and then I will multiply x by 2"),o(2e3).then(o=>{console.log("%c "+o,"color: blue"),e*=2,console.log("x * 2 = "+e)}).then(()=>console.warn("Give me a sec, I'm coming down and add 6 to x")).then(()=>o()).then(o=>{console.log("%c "+o,"color: blue"),e+=6,console.log("x + 6 = "+e)}).then(()=>{e-=1,console.log("x - 1 = "+e),document.querySelector("pre").innerText="x = "+e}).catch(e=>console.error(e));
//# sourceMappingURL=calculator_promise.js.map