0

So my task is this

Write a JavaScript program numbers1to10.js that prints on the console the numbers from 1 to 10 (each at a separate line). Run the program through Node.js. Example:

Command: node numbers1to10.js

Output: 1 2 3 4 5 6 7 8 9 10

I wrote the .js file called numbers1to10.js

function print1to10() {
for (var i = 1; i < 11; i++) {
    console.log(i);
}}

But i cant seem to open i trought nod.js

What do i have to do?

DAXaholic
  • 33,312
  • 6
  • 76
  • 74
Все Едно
  • 746
  • 3
  • 10
  • 24

1 Answers1

1

You don't call your function
Try:

function print1to10() {
for (var i = 1; i < 11; i++) {
    console.log(i);
}}
print1to10();
DAXaholic
  • 33,312
  • 6
  • 76
  • 74
  • Do you try to run it directly from within Visual Studio? If so then please try it by using a vanilla cmd.exe and running 'node 1.js' in the directory of 1.js as I assume your issue is caused by the IDE. I tried it both on Mac and Windows and it prints 1 to 10 on separate lines as expected ... – DAXaholic Mar 20 '16 at 14:55
  • You try to start node from ... node (your terminal show that is node ...) Open CMD and type "Node PathOfYourFile" – nodeover Aug 19 '17 at 12:06