Question: - Callbacks, Promises, Async / Await Consider the following JS code that does not work as intended: / / The following code does not work.

-Callbacks, Promises, Async/Await
Consider the following JS code that does not work as intended:
//The following code does not work. Make it work with callbacks first. Then with
// promises
function noAddGrunt(msg){
setTimeout((msg)=>{return msg+"";},1000);
}
function noAddSmack(msg){
setTimeout((msg)=>{return(""+msg)},1000);
}
function noAddBreath(msg){
setTimeout((msg)=>{return(msg+"")},1000);
}
let msg = "telephone";
let modded = noAddGrunt(msg);
modded = noAddSmack(modded);
modded = noAddBreath(modded);
console.log(modded); //expected outcome: telephone
Subtask A: Write a JS-file that fixes the above code using callback-functions, so that it logs to console
after 3 seconds:
telephone
The calls must happen one after another, meaning that after 1 second there exists an object named
msg with value telephone, after two seconds it becomes telephone and so
on...
Subtask B: Do the same as in Subtask A, but use Promises with .then-chaining instead of Callbacks
Subtask C: Do the same as in Subtask A, but use async/await-syntax instead of .then (you can still use
.then for the last Promise, if you need to)
- Callbacks, Promises, Async / Await Consider the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!