How to use readLine() in Javascript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

30th Dec 2020, 3:47 PM
Jesús Emmanuel Justo González
Jesús Emmanuel Justo González - avatar
4 Answers
+ 9
JavaScript do not have readLine() statement. The tests will be prepared in node.js.
30th Dec 2020, 3:53 PM
JaScript
JaScript - avatar
+ 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
13th Apr 2021, 4:50 PM
David Ordás
David Ordás - avatar
+ 1
Well, now everything has sense
30th Dec 2020, 4:04 PM
Jesús Emmanuel Justo González
Jesús Emmanuel Justo González - avatar
+ 1
If your js runs in the browser you can use prompt function to get an input from user
30th Dec 2020, 9:09 PM
Onur Can Gündoğdu
Onur Can Gündoğdu - avatar