Skip to content

Instantly share code, notes, and snippets.

@nodomw
Last active October 6, 2022 18:58
Show Gist options
  • Save nodomw/e6183b295157d60e57dcb9b0d80391a2 to your computer and use it in GitHub Desktop.
Save nodomw/e6183b295157d60e57dcb9b0d80391a2 to your computer and use it in GitHub Desktop.
deno calculator
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