javascript - 从用户 Javascript 获取 int

标签 javascript linux node.js input terminal

编辑>> readline 不起作用,在终端中收到此消息“ReferenceError:readline 未定义”

这里是 JavaScript 菜鸟

我正在编写一个程序,试图从用户那里获取一个 int 值。我通常知道如何在 HTML 文档中执行此操作,但是我在 Linux 计算机的终端中运行的 .js 文件中没有任何功能。

比如我想说

console.log("enter your number");
//code that collects the int named var yourint
console.log ("your number was " + yourint);

这真的很伤我的脑筋,因为我知道我只是在画一张空白,而解决方案是显而易见的。

最佳答案

console.log 将消息输出到Web 控制台而不是 shell

https://developer.mozilla.org/en-US/docs/Web/API/Console/log

如果你在 Linux 中使用 js24 它会抛出类似的错误

typein:1:0 ReferenceError: console is not defined

您可能想使用打印

示例

var input=readline('enter your number');
print('your number was '+input)

关于javascript - 从用户 Javascript 获取 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34559738/

相关文章:

javascript - $modal 弹出函数中的范围值未定义为对象

javascript - 在函数中创建react-router路由

linux - Font Awesome 和 i3bar

java - Tomcat 进程在交换空间用完后被 Linux 内核杀死;没有任何 JVM OutOfMemory 错误

node.js - 将请求记录到 Nodejs Express

node.js - Redis Cloud 和 connect-redis : the client is closed

javascript - 如何使用 wp_enqueue_script WordPress 将脚本添加为模块

Javascript RegExp 根据内容更改行

linux - 关于使用 bash/sed/awk 脚本重新排序网络路由文件的方法的思考

node.js - NodeJS 中的 TLS 连接使用证书存储中的证书和 key