+ 1

[HELP]why this code doesn't work?

my code works here fine but when I run this in intellij it doesn't even ask me to insert input and the IDE says process finished successfully. https://code.sololearn.com/ciEQ6YUhSqAT/?ref=app oh I just figured out that it doesn't work here so why it works in the javascript challenge(The Snail in well)? what's the difference between javascript and nodejs?

9th Dec 2020, 12:28 PM
hamid
hamid - avatar
7 Antworten
+ 3
hamid [Part 1 of answer] all right, readLine() does not work here (I don't really know why). Instead you need to use another approach. See this code as reference https://code.sololearn.com/coD91VH1Xvsd/?ref=app Explanation: stdin is the buffer which is used to get the input. In NodeJs, it can be accessed as an object through `process.stdin` Line 1: we define the string in which we will store the input Line 2: you set the encoding of the stdin to get utf-8 characters Line 3: `process.stdin.on('data', function)`. When input is given, this line gets executed and the function passed in as the 2nd argument is called with the input passed as argument in it . In the above code, we pass in a function which takes an argument `data`. When input will be entered, the function will be called and `data` will have the value of the input. We simply add the input to the `input` variable we defined in the first line.
9th Dec 2020, 1:10 PM
XXX
XXX - avatar
+ 3
[Part 2 of answer] Line 6: `process.stdin.on('end', function)`. When the user has finished entering the input, the function passed in as 2nd argument will be called. In the above code we simply call the main function with the value of the `input` variable. Line 10: here I have changed the definition of `main` to take an argument `input`
9th Dec 2020, 1:11 PM
XXX
XXX - avatar
+ 2
I don't know how it works in IntelliJ, but you have to call the main() function. Add this line at the bottom-most of your code - main();
9th Dec 2020, 12:35 PM
XXX
XXX - avatar
+ 1
Sof💕 what do you mean? I didn't get at all
9th Dec 2020, 12:39 PM
hamid
hamid - avatar
0
XXX when I tried it I receive the famous anonymous error.
9th Dec 2020, 12:36 PM
hamid
hamid - avatar
0
Try again!😊 I do it(use only one while)
9th Dec 2020, 12:37 PM
Սոֆի
0
Ok nothing You must do it!
9th Dec 2020, 12:40 PM
Սոֆի