+ 2
Why doesn't parseInt(readLine()) work in VS code but works in sololearn JS console?
I tried the following code in VScode var m = parseInt(readLine(),10); And it returned readLine is not defined. After some research I first added the line: const readLine = require('readline'); And now VScode terminal shows error readLine is not a function because it's a class. Why doesn't it work in VScode. Also how else to take the input from user in VScode?
4 Answers
+ 3
VS is only an editor.
readLine is a function used by sololearn to get user input.
Maybe you can use prompt().
(edited)
+ 1
You have to import the readline module beforehand in Nodejs Application & also, it is an async function which takes object as an argument.
readline.createInterface({ input, output });
doc : https://nodejs.org/api/readline.html
+ 1
Martin Taylor
Well, I admit, I don't know how sololearn handles input or node.js. I hypothesized it would be related to node.js as in the sololearn course they always use node.js playground scripts for user input (instead of the usual web script)...
edit:
I edited my initial comment. Maybe someone finds this thread helpful:
https://www.sololearn.com/Discuss/2866976/?ref=app