To understand async/await, I am trying to display a console message once settimeout runs and expires. How do I fix my code below? I have 5 settimeout function and each should display respective message once finished.
function t1(){
setTimeout(() => {
console.log("1")
}, 1000);
}
function t2(){
setTimeout(() => {
console.log("2")
}, 2000);
}
function t3(){
setTimeout(() => {
console.log("3")
}, 3000);
}
function t4(){
setTimeout(() => {
console.log("4")
}, 4000);
}
function t5(){
setTimeout(() => {
console.log("5")
}, 5000);
}
async function main(){
await t1();
console.log("1sec done");
await t2();
console.log("2sec done");
await t3();
console.log("3sec done");
await t4();
console.log("4sec done");
await t5();
console.log("Yay! I am all done");
}
main();