I'm struggling to wrap my head around the concept of async and promises in js. I can't figure out why the code below doesn't print anything on my console.
I'm assuming it's because the code inside my Promise is not asynchronous, but isn't that the point of a promise: to make something synchronous become asynchronous?
If that's not the case, how could I truly "transform" a sync code into async without using any built in js functions (setTimeOut,etc)?
function countdown(seconds) {
return new Promise(function(resolve, reject) {
for (let i = seconds; i >= 0; i--) {
if (i > 0) console.log(i + '...');
else resolve(console.log("GO!"));
}
}
};
count = countdown(5).then(() => console.log('Completed'), (err) => console.log(err.message));