Why is NodeJS not calculating the value?How to make a function wait until a callback has been called using node.jsHow can I update NodeJS and NPM to the next versions?How to run a hello.js file in Node.js on windows?What is this Javascript “require”?How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)NodeJS - What does “socket hang up” actually mean?Unexpected results when working with very big integers on interpreted languagestypescript getting error TS2304: cannot find name ' require'Babel 6 regeneratorRuntime is not definedHow, in general, does Node.js handle 10,000 concurrent requests?
Does Google Maps take into account hills/inclines for route times?
Was I subtly told to resign?
How does a Potion of Poison work?
How is angular momentum conserved for the orbiting body if the centripetal force disappears?
How might the United Kingdom become a republic?
<schwitz>, <zwinker> etc. Does German always use 2nd Person Singular Imperative verbs for emoticons? If so, why?
PIC12F675 GP4 doesn't work
Why do players in the past play much longer tournaments than today's top players?
Why do Americans say "less than five people"?
Can fluent English speakers distinguish “steel”, “still” and “steal”?
Who Can Help Retag This?
Drawing color tiles using Tikz
The monorail explodes before I can get on it
Get ids only where one id is null and other isn't
Why was hardware diversification an asset for the IBM PC ecosystem?
Shortest distance around a pyramid?
When did the Roman Empire fall according to contemporaries?
How did the hit man miss?
What are some examples of special things about Russian?
Are unclear "take-it or leave-it" contracts interpreted in my favor?
How do you create draggable points inside a graphic image?
Is an acid a salt or not?
Was lunar module "pilot" Harrison Schmitt legally a "pilot" at the time?
Supporting developers who insist on using their pet language
Why is NodeJS not calculating the value?
How to make a function wait until a callback has been called using node.jsHow can I update NodeJS and NPM to the next versions?How to run a hello.js file in Node.js on windows?What is this Javascript “require”?How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)NodeJS - What does “socket hang up” actually mean?Unexpected results when working with very big integers on interpreted languagestypescript getting error TS2304: cannot find name ' require'Babel 6 regeneratorRuntime is not definedHow, in general, does Node.js handle 10,000 concurrent requests?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to get this simple console Node.js calculator to work, but it just won't return any value. Any insight into what I'm doing wrong?
console.log(process.argv);
var x = 0;
if (process.argv[4]==="+"||process.argv[4]==="plus")x=parseInt(process.argv[3])+parseInt(process.argv[5])
if (process.argv[4]==="-"||process.argv[4]==="minus")x=parseInt(process.argv[3])-parseInt(process.argv[5])
if (process.argv[4]==="*"||process.argv[4]==="times")x=parseInt(process.argv[3])*parseInt(process.argv[5])
if (process.argv[4]==="/"||process.argv[4]==="over")x=parseInt(process.argv[3])/parseInt(process.argv[5])
console.log(x);
node.js
add a comment |
I am trying to get this simple console Node.js calculator to work, but it just won't return any value. Any insight into what I'm doing wrong?
console.log(process.argv);
var x = 0;
if (process.argv[4]==="+"||process.argv[4]==="plus")x=parseInt(process.argv[3])+parseInt(process.argv[5])
if (process.argv[4]==="-"||process.argv[4]==="minus")x=parseInt(process.argv[3])-parseInt(process.argv[5])
if (process.argv[4]==="*"||process.argv[4]==="times")x=parseInt(process.argv[3])*parseInt(process.argv[5])
if (process.argv[4]==="/"||process.argv[4]==="over")x=parseInt(process.argv[3])/parseInt(process.argv[5])
console.log(x);
node.js
add a comment |
I am trying to get this simple console Node.js calculator to work, but it just won't return any value. Any insight into what I'm doing wrong?
console.log(process.argv);
var x = 0;
if (process.argv[4]==="+"||process.argv[4]==="plus")x=parseInt(process.argv[3])+parseInt(process.argv[5])
if (process.argv[4]==="-"||process.argv[4]==="minus")x=parseInt(process.argv[3])-parseInt(process.argv[5])
if (process.argv[4]==="*"||process.argv[4]==="times")x=parseInt(process.argv[3])*parseInt(process.argv[5])
if (process.argv[4]==="/"||process.argv[4]==="over")x=parseInt(process.argv[3])/parseInt(process.argv[5])
console.log(x);
node.js
I am trying to get this simple console Node.js calculator to work, but it just won't return any value. Any insight into what I'm doing wrong?
console.log(process.argv);
var x = 0;
if (process.argv[4]==="+"||process.argv[4]==="plus")x=parseInt(process.argv[3])+parseInt(process.argv[5])
if (process.argv[4]==="-"||process.argv[4]==="minus")x=parseInt(process.argv[3])-parseInt(process.argv[5])
if (process.argv[4]==="*"||process.argv[4]==="times")x=parseInt(process.argv[3])*parseInt(process.argv[5])
if (process.argv[4]==="/"||process.argv[4]==="over")x=parseInt(process.argv[3])/parseInt(process.argv[5])
console.log(x);
node.js
node.js
asked Mar 26 at 3:38
OlegArsyonovOlegArsyonov
4681 gold badge4 silver badges14 bronze badges
4681 gold badge4 silver badges14 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The array indexing on Javascript starts from 0 and not 1. Also it is best to handle divide by zero condition.
console.log(process.argv);
var x = 0;
if (process.argv[3] === "+" || process.argv[3] === "plus")
x = parseInt(process.argv[2]) + parseInt(process.argv[4]);
if (process.argv[3] === "-" || process.argv[3] === "minus")
x = parseInt(process.argv[2]) - parseInt(process.argv[4]);
if (process.argv[3] === "*" || process.argv[3] === "times")
x = parseInt(process.argv[2]) * parseInt(process.argv[4]);
if (process.argv[3] === "/" || process.argv[3] === "over")
x = parseInt(process.argv[2]) / parseInt(process.argv[4]);
console.log(x);
Thank you. I should have thought about it!
– OlegArsyonov
Mar 26 at 3:49
1
@OlegArsyonov, did this solve your problem? If yes, kindly accept the answer. Else, state what else or more is needed.
– Rai
Mar 26 at 5:31
@OlegArsyonov instead of all if statements, use if, else if ..... that will be a little more efficient.
– Pankaj Jindal
Mar 26 at 5:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55349508%2fwhy-is-nodejs-not-calculating-the-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The array indexing on Javascript starts from 0 and not 1. Also it is best to handle divide by zero condition.
console.log(process.argv);
var x = 0;
if (process.argv[3] === "+" || process.argv[3] === "plus")
x = parseInt(process.argv[2]) + parseInt(process.argv[4]);
if (process.argv[3] === "-" || process.argv[3] === "minus")
x = parseInt(process.argv[2]) - parseInt(process.argv[4]);
if (process.argv[3] === "*" || process.argv[3] === "times")
x = parseInt(process.argv[2]) * parseInt(process.argv[4]);
if (process.argv[3] === "/" || process.argv[3] === "over")
x = parseInt(process.argv[2]) / parseInt(process.argv[4]);
console.log(x);
Thank you. I should have thought about it!
– OlegArsyonov
Mar 26 at 3:49
1
@OlegArsyonov, did this solve your problem? If yes, kindly accept the answer. Else, state what else or more is needed.
– Rai
Mar 26 at 5:31
@OlegArsyonov instead of all if statements, use if, else if ..... that will be a little more efficient.
– Pankaj Jindal
Mar 26 at 5:53
add a comment |
The array indexing on Javascript starts from 0 and not 1. Also it is best to handle divide by zero condition.
console.log(process.argv);
var x = 0;
if (process.argv[3] === "+" || process.argv[3] === "plus")
x = parseInt(process.argv[2]) + parseInt(process.argv[4]);
if (process.argv[3] === "-" || process.argv[3] === "minus")
x = parseInt(process.argv[2]) - parseInt(process.argv[4]);
if (process.argv[3] === "*" || process.argv[3] === "times")
x = parseInt(process.argv[2]) * parseInt(process.argv[4]);
if (process.argv[3] === "/" || process.argv[3] === "over")
x = parseInt(process.argv[2]) / parseInt(process.argv[4]);
console.log(x);
Thank you. I should have thought about it!
– OlegArsyonov
Mar 26 at 3:49
1
@OlegArsyonov, did this solve your problem? If yes, kindly accept the answer. Else, state what else or more is needed.
– Rai
Mar 26 at 5:31
@OlegArsyonov instead of all if statements, use if, else if ..... that will be a little more efficient.
– Pankaj Jindal
Mar 26 at 5:53
add a comment |
The array indexing on Javascript starts from 0 and not 1. Also it is best to handle divide by zero condition.
console.log(process.argv);
var x = 0;
if (process.argv[3] === "+" || process.argv[3] === "plus")
x = parseInt(process.argv[2]) + parseInt(process.argv[4]);
if (process.argv[3] === "-" || process.argv[3] === "minus")
x = parseInt(process.argv[2]) - parseInt(process.argv[4]);
if (process.argv[3] === "*" || process.argv[3] === "times")
x = parseInt(process.argv[2]) * parseInt(process.argv[4]);
if (process.argv[3] === "/" || process.argv[3] === "over")
x = parseInt(process.argv[2]) / parseInt(process.argv[4]);
console.log(x);
The array indexing on Javascript starts from 0 and not 1. Also it is best to handle divide by zero condition.
console.log(process.argv);
var x = 0;
if (process.argv[3] === "+" || process.argv[3] === "plus")
x = parseInt(process.argv[2]) + parseInt(process.argv[4]);
if (process.argv[3] === "-" || process.argv[3] === "minus")
x = parseInt(process.argv[2]) - parseInt(process.argv[4]);
if (process.argv[3] === "*" || process.argv[3] === "times")
x = parseInt(process.argv[2]) * parseInt(process.argv[4]);
if (process.argv[3] === "/" || process.argv[3] === "over")
x = parseInt(process.argv[2]) / parseInt(process.argv[4]);
console.log(x);
answered Mar 26 at 3:46
PrivateOmegaPrivateOmega
1,2476 silver badges18 bronze badges
1,2476 silver badges18 bronze badges
Thank you. I should have thought about it!
– OlegArsyonov
Mar 26 at 3:49
1
@OlegArsyonov, did this solve your problem? If yes, kindly accept the answer. Else, state what else or more is needed.
– Rai
Mar 26 at 5:31
@OlegArsyonov instead of all if statements, use if, else if ..... that will be a little more efficient.
– Pankaj Jindal
Mar 26 at 5:53
add a comment |
Thank you. I should have thought about it!
– OlegArsyonov
Mar 26 at 3:49
1
@OlegArsyonov, did this solve your problem? If yes, kindly accept the answer. Else, state what else or more is needed.
– Rai
Mar 26 at 5:31
@OlegArsyonov instead of all if statements, use if, else if ..... that will be a little more efficient.
– Pankaj Jindal
Mar 26 at 5:53
Thank you. I should have thought about it!
– OlegArsyonov
Mar 26 at 3:49
Thank you. I should have thought about it!
– OlegArsyonov
Mar 26 at 3:49
1
1
@OlegArsyonov, did this solve your problem? If yes, kindly accept the answer. Else, state what else or more is needed.
– Rai
Mar 26 at 5:31
@OlegArsyonov, did this solve your problem? If yes, kindly accept the answer. Else, state what else or more is needed.
– Rai
Mar 26 at 5:31
@OlegArsyonov instead of all if statements, use if, else if ..... that will be a little more efficient.
– Pankaj Jindal
Mar 26 at 5:53
@OlegArsyonov instead of all if statements, use if, else if ..... that will be a little more efficient.
– Pankaj Jindal
Mar 26 at 5:53
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55349508%2fwhy-is-nodejs-not-calculating-the-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown