Promises 01
const promisedNumber = () => {
return new Promise((resolve, reject) => {
const randomNumber = Math.floor(Math.random() * 10);
if (randomNumber <= 4) {
resolve(`Valid number (${randomNumber})`);
} else {
reject(`Invalid number (${randomNumber})`);
}
});
};
Create a function sweetPromisedNumber
that is the exact equivalent of the function
promisedNumber
but with the syntactic sugar keywords
async
/await
.
Your function should look like this:
const sweetPromisedNumber = async () => {
};
To see the solution, enter a valid code or purchase one: