Javascript: how do you enter a user and save it in a variable without any HTML code?

I want to ask the user to enter the number through the console. Then I want to save it in a variable to use it for a function, etc. Here is an example of what I did. When I do this, it says ReferenceError: readline is not defined

console.log("Enter your guess and press <Enter>: /t" );
var userNumber = readline();

I'm just trying to create an interactive js console application.

Edit: Here is my source code http://repl.it/NeI/4

+3
source share
3 answers

Try to do this:

var guess = window.prompt("Enter your guess", "Number from 1 to 9");
console.log(guess);
+11
source

The console does not do what you hope in this situation.

- API Mozilla Chrome.

- .

+3

Developer tools or the Firebug console cannot receive user data in this way, there are no methods reador readline. You should use a window method called "prompt".

var data = prompt("Type something to me baby!");
console.log(data);

Here is another question regarding the same doubt.

0
source

All Articles