Amazon interview question

Write a function with Async and Await.

Interview Answer

Anonymous

6 July 2021

//Call timer function that return result after 3 seconds countTimer() { return new Promise( (resolve) => { setTimeout( () => { resolve('The time is up!'); }, 3000 ); }) }; //Start Timer async startTimer(){ console.log('Timer activated'); const result = await countTimer(); console.log('result'); }; startTimer();

1