+ 2
How to use readLine() in Javascript
I'm trying to solve the excercises in JavaScript, supposedly the input is already defined, but when I try to use that value, I simply can't do it, I wrote my code in an online compiler and says "Uncaught ReferenceError: readline isn't defined" and I don't know how to solve that error, I searched online but simply the error isn't fixed, please Help me
5 Antworten
+ 9
JavaScript do not have readLine() statement.
The tests will be prepared in node.js.
+ 3
Jesús Emmanuel Justo González I suppose you are trying in NodeJS?
Martin Taylor JaScript
In lesson practices the test environment provides you a readLine() function, and also force you have a main() function
But in code playground it doesn't exists.
You need to read buffered and synchronous from process.stdin
https://code.sololearn.com/cEk3cZOIJ5h2/?ref=app
or use the readline built-in module (callbacks/promises)
https://code.sololearn.com/c9FOBbJcgnw0/?ref=app
NOTE: Codes above are some of my experiments and therefore must be take as is, can have some bugs and of course, be improved.
Some usefull doc/libs outside SoloLearn:
https://nodejs.org/api/readline.html
https://nodejs.org/api/fs.html
https://github.com/anseki/readline-sync
+ 1
Well, now everything has sense
+ 1
If your js runs in the browser you can use prompt function to get an input from user