#! /usr/bin/env node import inquirer from "inquirer"; import chalk from "chalk"; import chalkAnimation from "chalk-animation"; import { type } from "os"; const sleep = ()=>{ return new Promise((res)=>{ setTimeout(res, 2000); }) } async function welcome(){ let rainbowTitle=chalkAnimation.rainbow('Welcome to my calculator'); await sleep(); rainbowTitle.stop(); console.log(` ----------------------------- | ------------------------ | | | 0. | | | | | | | ------------------------- | | | 7 | 8 | 9 | | + | | | ------------------------- | | | 4 | 5 | 6 | | - | | | ------------------------ | | | 1 | 2 | 3 | | * | | | ------------------------ | | |. | 0 | "" | | / | | | ----------------------- | ------------------------------- `); } await welcome(); async function askQuestion(){ await inquirer .prompt([ { type: "list", name: "operators", message: "Which operations you want to perform?", choices:["Addition", "subtraction","Multiplication", "division"] }, { type: "number", name: "num1", message: "Enter number 1", }, { type: "number", name: "num2", message: "Enter number 2", } ]) .then((answers) => { // console.log(answers); if(answers.operators == "Addition"){ console.log(`${answers.num1} + ${answers.num2} = ${answers.num1 + answers.num2}`); } else if(answers.operators == "subtraction"){ console.log(`${answers.num1} - ${answers.num2} = ${answers.num1 - answers.num2}`); } else if(answers.operators == "Multiplication"){ console.log(`${answers.num1} * ${answers.num2} = ${answers.num1 * answers.num2}`); } else if(answers.operators == "division"){ console.log(`${answers.num1} / ${answers.num2} = ${answers.num1 / answers.num2}`); } }) }; async function startagain(){ do{ await askQuestion(); var again = await inquirer .prompt({ type:"input", name : "restart", message: "Do you want to restart? Press y or n ", }) }while(again.restart == 'y' || again.restart == 'Y' || again.restart == 'yes') } startagain();