Javascript:如何在没有任何 HTML 的情况下获取用户输入并将其存储到变量中?
问题描述:
我想通过控制台要求用户输入一个数字.然后我想将它存储到一个变量中以将它用于函数等.这是我所做的一个例子.当我这样做时,它说 ReferenceError: readline is not defined
I want to ask the user through the console to enter a number. I then want to store it into a variable to have it used for a function etc. Here is an example of what I have done. When i do this it says ReferenceError: readline is not defined
console.log("Enter your guess and press <Enter>: /t" );
var userNumber = readline();
我现在只是想创建一个交互式 js 控制台应用程序.
I am just trying to create an interactive js console app for now.
这是我的源代码 http://repl.it/NeI/4
答
尝试这样做:
var guess = window.prompt("Enter your guess", "Number from 1 to 9");
console.log(guess);