+ 2

[not solved yet?] Space between name and parameters: Sololearn node.js interpreter bug, node.js specification or something else?

I was completing projects for JavaScript. While I was doing Currency Converter project, I decided function definitions in my code (and pre-written main function) to be thus: `function name (parameters) {` (including space between name and parentheses), as it is better for me. But there was no output. After a few tries, I removed the spaces between function names and parameters and got it right. So, the problem was in this. But why? Is it Sololearn interpreter bug, part of node.js syntax or something else?

9th May 2021, 9:39 AM
#0009e7 [get]
#0009e7 [get] - avatar
5 Answers
+ 3
XXX, [Spoiler Alert for those who did not do the project yet] function convert (a, r) { return a * r; } function main () { var amount = parseFloat(readLine(), 10); var rate = parseFloat(readLine(), 10); console.log(convert(amount, rate)); } Also, I experimented with it before copying and found out that the problem is in "main ()" (works fine with "main()").
9th May 2021, 10:46 AM
#0009e7 [get]
#0009e7 [get] - avatar
+ 2
get Hmm.... that's weird. It works as a normal Node.js code and as a web code. The fact that nothing is output-ed means that the main() function is never called. I can think of only one explanation to this- As far as I know, SoloLearn uses some sort of code analyzer in code coaches for some languages (for god knows what reason). So I'm guessing that the analyzer is buggy and thinks that main() function does not exist and ends up not running any code at all. This sounds very unlikely mainly because this is not a problem with any of the other languages. And as far as I know, JavaScript doesn't have the code analyzer yet. Maybe I'm just thinking too much (saying this because I've boldly assumed things to be bugs before, only to find later that their behaviour was totally obvious), but I'll say it is a bug mainly because it works as a normal Node.js or web code.
9th May 2021, 11:34 AM
XXX
XXX - avatar
+ 2
get Don't mark my answer as best yet. Let's keep the thread open for answers from others.
9th May 2021, 11:52 AM
XXX
XXX - avatar
+ 2
While I was reviewing this question, I decided to check it again and
 it is not solved yet. I have experimented with the code and it appears that when you set a parameter with a default value to the "main" function, it also outputs nothing. Seems that the interpreter just literally searches for "function main() {" and executes the code after it. [edit] But it seems to accept any other changes in code, so I still am confused about this.
28th Nov 2021, 8:25 AM
#0009e7 [get]
#0009e7 [get] - avatar
+ 1
It worked fine for me. Could you make a code where the problem is there for you?
9th May 2021, 9:48 AM
XXX
XXX - avatar