Implement the code for Meditation
class to be used as follows:
const morning_meditation = new Meditation(5);
morning_meditation.start();
console.log(`Start meditation`);
// Start meditation
// 5
// 4
// 3
// 2
// 1
// Jay Guru Dev
Change isPrime
function below to run asynchronously using Promise.
- if the input is prime number, the promise resolves with
{ prime: true }
. - if the input is not a prime number, it rejects with
{ prime: false }
.
const isPrime = (n: number) => {
for (let i = 2, s = Math.sqrt(n); i <= s; i++)
if (n % i === 0) return false;
return n > 1;
};
When you finish, test using the code below:
console.log('start');
isPrime(7)
.then(console.log)
.catch(console.error);
console.log('end');
// start
// end
// { prime: true }
Make changes to provided test and use async
/await
instead of .then()
and .catch()
Write an IIFE that fetch recipes from https://dummyjson.com/recipes
and print to the console a list of recipe names.
Make sure you type the response.