简体   繁体   English

从Node.js打开脚本(.js)

[英]Open a script (.js) from Node.js

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). 编写一个JavaScript程序number1to10.js,该程序在控制台上打印从1到10的数字(每个数字在单独的一行中)。 Run the program through Node.js. 通过Node.js运行程序。 Example: 例:

Command: node numbers1to10.js 命令:节点编号1to10.js

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

I wrote the .js file called numbers1to10.js 我写了一个名为numbers1to10.js的.js文件

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

But i cant seem to open i trought nod.js 但是我似乎无法打开我努力了nod.js

What do i have to do? 我需要做什么?

You don't call your function 您不调用函数
Try: 尝试:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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