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

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현