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;








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);









share|improve this question




























    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);









    share|improve this question
























      0












      0








      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);









      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 26 at 3:38









      OlegArsyonovOlegArsyonov

      4681 gold badge4 silver badges14 bronze badges




      4681 gold badge4 silver badges14 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          1














          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);





          share|improve this answer























          • 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










          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
          );



          );













          draft saved

          draft discarded


















          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









          1














          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);





          share|improve this answer























          • 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















          1














          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);





          share|improve this answer























          • 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













          1












          1








          1







          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);





          share|improve this answer













          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);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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

















          • 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








          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.



















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript