- Open your command-line application and navigate to your workspace.
- Create a new folder named 4-02-await-async-results.
- Copy or create an index.html that loads and runs a main function from main.js.
- Create a main.js with an async function named getRandomNumber that returns a random number:
// main.js
async function getRandomNumber () {
return Math.random();
}
- Create an async function, main, that calls getRandomNumber, waits for the result, and logs out the value:
export async function main () {
console.log('before task');
const result = await getRandomNumber();
console.log('Received the value: %s', result);
console.log('after task completed');
}
- Start you Python web server and open the following link in your browser:
http://localhost:8000/.
- You should see the following output: