Created
May 12, 2022 20:35
-
-
Save maxmatthews/c12e622e500f5fa4c73f04adc388210e to your computer and use it in GitHub Desktop.
Tip Calculator Terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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