Skip to content

Instantly share code, notes, and snippets.

@achimbode
Forked from arol/async.js
Created December 1, 2017 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achimbode/5e60c100f4cb7c0e3aac7e5a0bcb14cd to your computer and use it in GitHub Desktop.
Save achimbode/5e60c100f4cb7c0e3aac7e5a0bcb14cd to your computer and use it in GitHub Desktop.
Asynchronicity exercise
const randomNumber = () => {
return Math.random();
}
// 1. Make it wait for 1 sec. with `setTimeout`
const timeoutRandomNumber = () => {
}
// 2. Now wrap the timeout version to work with promises
const promiseRandomNumber = () => {
}
// 3. Finally, code a final version with async await.
const asyncRandomNumber = () => {
}
const rangedRandomNumber = (base, min, max) => {
return Math.floor((base*(max-min))+min);
}
const main = () => {
const rnd = randomNumber()
console.log(rangedRandomNumber(rnd, 14, 42));
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment