You can use a for loop for this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/ Reference/Statements/for
Use the initialization expression to set the index you want to start at (var i = 2) then test for the end of the array (i < process.argv.length) in the condition expression, increment the index in the "final" expression, and add the value at each index to a running total in the block statement. Hope that helps. I left out the specific code so you could learn it on your own, but if you just want to see the code that does it, let me know. -John On Aug 10, 2017 11:19 AM, "Stephany Prodromos" <[email protected]> wrote: Hi guys I just started learning node today, and am a little confused as to how to go about the second exercise.... at first i had: var num1 = +process.argv[2]; var num2 = +process.argv[3]; var result = num1 + num2; console.log(result); ...but this will only work for 2 numbers. any ideas on how to loop through process.argv to account for multiple number inputs?? -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation- policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting- Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/ms gid/nodejs/6ea4fd6a-acb3-497e-898b-ff7b32a99f2c%40googlegroups.com <https://groups.google.com/d/msgid/nodejs/6ea4fd6a-acb3-497e-898b-ff7b32a99f2c%40googlegroups.com?utm_medium=email&utm_source=footer> . For more options, visit https://groups.google.com/d/optout. -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAMbK04wpyGHKhUf9e3Kn0xkO%2BvsZU2%3D4bi8h3tP66iRGW-pMMQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
