Open your command-line application and navigate to your workspace.
Create a new folder named 04-03-async-function-Promise-chain.
Copy or create an index.html that loads and runs a main function from main.js.
Create an async function, getRandomNumber, that returns a random number:
async function getRandomNumber() {
console.log('Getting random number.');
return Math.random();
}
Create an async function, determinReadyToLaunch, that returns true if its first argument is greater than 0.5:
async function deteremineReadyToLaunch(percentage) {
console.log('Determining Ready to launch.');
return Math.random() > 0.5;
}
Create a third async function, reportResults, that logs out different results if its first argument is true or false:
async function reportResults(isReadyToLaunch) {
if (isReadyToLaunch) {
console.log('Rocket ready to launch. Initiate countdown: ');
} else {
console.error('Rocket not ready. Abort mission: ');
}
}
Create a main function that calls getRandomNumber, and a chain of the Promise it creates to call determineReadyToLaunch and reportResults in succession: