简体   繁体   中英

JavaScript: Console not logging without error message

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM