0

Javascript course has lot of errors

If not done yet, you should read users comments, few of them points out errors with exercises, but the one that disappointed me is the one with the Verification PRO exercise. We can not resolve it and continue with because of the prompt function, here you have the complete message I got: /usercode/file0.js:1 let pin = Number(prompt("Enter pin:")); ^ ReferenceError: prompt is not defined at Object.<anonymous> (/usercode/file0.js:1:11) at Module._compile (node:internal/modules/cjs/loader:1254:14) at Module._extensions..js (node:internal/modules/cjs/loader:1308:10) at Module.load (node:internal/modules/cjs/loader:1117:32) at Module._load (node:internal/modules/cjs/loader:958:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:23:47 Node.js v18.16.0

10th Feb 2024, 7:19 AM
Atok
Atok - avatar
8 Respuestas
+ 2
Based on your question. The error seems valid. The course has it wrong
10th Feb 2024, 9:37 PM
Toni Isotalo
Toni Isotalo - avatar
+ 2
What do you mean nodejs? prompt is not originally part of javascript. Its part of the window object and can only be run in the browser. If you are trying to use it with nodejs, it doesnt exist. It comes with prompt-sync module.
10th Feb 2024, 9:34 PM
Toni Isotalo
Toni Isotalo - avatar
0
I don't have PRO access, but the error message is saying "prompt is not defined". Should it be "parseInt(readLine(), 10)" or something similar to read integer input from the system?
10th Feb 2024, 8:25 AM
Wong Hei Ming
Wong Hei Ming - avatar
0
You should remove Number from prompt like this....... let pin = prompt("Enter pin:");
10th Feb 2024, 9:49 AM
Jan
Jan - avatar
0
Hmm...I think I misunderstood that question. Could you please link to the course and what lesson it is instead. I forgot SL uses node for the javascript courses, and of course prompt doesn't work there. Please, link to the course and lesson instead.
11th Feb 2024, 9:01 AM
Jan
Jan - avatar
0
...and by the way, the special input method with readLine that SL uses in the javascript courses doesn't work in code bits created on the playground. It only works in the javascript courses... It's another and more comprehensive code if you want an input method in node in general...
11th Feb 2024, 10:47 AM
Jan
Jan - avatar
0
It's actually possible to use prompt in node, but it requires an npm package called "prompt-sync", but that package is not available on SL, and then there is a callback function that actually works on SL, but it contains too much code, and you also have to hit enter before you click "Submit", so that is not a good choice, but it works without problems on a pc.
11th Feb 2024, 8:09 PM
Jan
Jan - avatar
0
You can try the callback function here, but you need to hit enter, before clicking "Submit" after you have typed something...... https://sololearn.com/compiler-playground/cHiasqESKLmc/?ref=app
11th Feb 2024, 8:51 PM
Jan
Jan - avatar