Skip to content

Instantly share code, notes, and snippets.

@maxmatthews
Created May 12, 2022 20:35
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 maxmatthews/c12e622e500f5fa4c73f04adc388210e to your computer and use it in GitHub Desktop.
Save maxmatthews/c12e622e500f5fa4c73f04adc388210e to your computer and use it in GitHub Desktop.
Tip Calculator Terminal
const prompts = require("prompts");
(async () => {
let keepRunning = true;
while (keepRunning) {
const answers = await prompts([
{
name: "total",
type: "number",
message: "What was the total bill?",
float: true,
},
{ name: "tip", type: "number", message: "How much you tippin?" },
]);
const tipAmount = answers.total * (answers.tip / 100);
console.log(
"Your tip should be $" +
tipAmount +
". For a total of $" +
(answers.total + tipAmount)
);
const keepRunningPrompt = await prompts({
name: "keepRunningAnswer",
message: "Would you like to calculate another tip?",
type: "toggle",
initial: true,
active: "Yea, let's go!",
inactive: "No, I'm done calculatin'",
});
keepRunning = keepRunningPrompt.keepRunningAnswer;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment