Last active
October 6, 2022 18:58
-
-
Save nodomw/e6183b295157d60e57dcb9b0d80391a2 to your computer and use it in GitHub Desktop.
deno calculator
This file contains 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 modes = { | |
'addition': (a: number, b: number) => a + b, | |
'subtraction': (a: number, b: number) => a - b, | |
'multiplication': (a: number, b: number) => a * b, | |
'division': (a: number, b: number) => a / b, | |
}; | |
const mode = prompt( | |
`Welcome to the calculator!\nPlease select a mode (${Object.keys(modes)}:`, | |
'addition', | |
); | |
const firstNumber = Number(prompt('Please enter the first number:', '420')); | |
const secondNumber = Number(prompt('Please enter the second number:', '360')); | |
console.log( | |
eval('modes[\'' + mode + '\'](' + firstNumber + ', ' + secondNumber + ')'), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment