Created
April 30, 2017 16:29
-
-
Save gorkamu/d245706d3231bacadf2a19cb0f0ffb9a to your computer and use it in GitHub Desktop.
Example of a simple calculator in js
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
'use strict' | |
var args = process.argv.slice(2); | |
var result = null; | |
if(args.length == 3){ | |
var num1 = parseFloat(args[0]); | |
var operation = args[1]; | |
var num2 = parseFloat(args[2]); | |
switch(operation){ | |
case "+": | |
result = parseFloat(num1+num2); | |
break; | |
case "-": | |
result = parseFloat(num1-num2); | |
break; | |
case "*": | |
result = parseFloat(num1*num2); | |
break; | |
case "/": | |
result = parseFloat(num1/num2); | |
break; | |
} | |
} | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment