0

I made a simple function to illustrate my problem

I ran this code on Windows Powershell with Node.js, not on a browser. It doesn't log anything to the console. What am I doing wrong? I was just goofing around testing stuff. This is the only code in the file, nothing else.

var sigma = function(nums) {
  var i = 0;
  var ops = nums.length - 1;
  var sum = 0;
  while (i <= ops) {
    sum += nums[i];
    i += 1;
  }
console.log(sum);
};
sigma([1, 2, 3, 4, 5]);
ShadeOfLight
  • 87
  • 11
  • How do you execute the code? – mplungjan May 08 '20 at 06:08
  • Possible answer? https://stackoverflow.com/a/49507426/295783 – mplungjan May 08 '20 at 06:10
  • If I run node test.js (I named my file with your contents test.js) I get two logged lines "89" and "This also doesn't work". What I also found odd was that my node binaries weren't linked properly so I updated them with brew. I don't know if you also use mac, but if yes maybe you have a similar issue? – jPO May 08 '20 at 06:28
  • Sorry, I don't really understand what you mean by 'node binaries'. Could you please clarify? – ShadeOfLight May 09 '20 at 05:18

1 Answers1

0

Did you install node in your environment ?

I means for javascript code you need to first compiled it.

Maybe after installing node environment , You need run it

> node sigma.js

Mangesh55
  • 31
  • 4