Author | Message |
---|---|
Darren76
Posts: 39
|
Posted 18:54 Sep 09, 2016 |
console.log("Hello user!"); When I run this code on the cmd line after saving it as a .js file, it keeps giving me an error saying that your prompt not defined. What should I do? Thanks!
|
Japaric4
Posts: 6
|
Posted 18:56 Sep 09, 2016 |
Can you post a screen cap of your console? |
JackStrauss
Posts: 236
|
Posted 19:13 Sep 09, 2016 |
Don't we use readLine to accept input from the command line? |
JackStrauss
Posts: 236
|
Posted 19:17 Sep 09, 2016 |
I think the error here is that when you use var num = Prompt(.."Enter integer"..); console.log("...Number picked is..." + num);
You get the error because no integer has been entered, so there exist no integer to read.
|
JackStrauss
Posts: 236
|
Posted 19:18 Sep 09, 2016 |
Never mind, lol. I just tried it, and it didn't work on my console either. |
JackStrauss
Posts: 236
|
Posted 19:20 Sep 09, 2016 |
Try to define it before you use it. This is the error you are getting. |
Miro138
Posts: 22
|
Posted 19:22 Sep 09, 2016 |
I think you have to use the "rl" that was provided in the started code. Since its command line, in order to get input it needs special functions to read user input. I dont think it works the same as it does in a browser. For example, Using the starter code you could : rl.setPrompt("Testing");
Which will take user input and then the console will print it. |
JackStrauss
Posts: 236
|
Posted 19:23 Sep 09, 2016 |
Here is a screen cap. My most immediate guess is to define the prompt before you use it.
I went through each line.
The undefined error appears twice, but one appears to throw an exception.
Last edited by JackStrauss at
19:24 Sep 09, 2016.
|
msargent
Posts: 519
|
Posted 20:53 Sep 09, 2016 |
"console.log("Hello user!"); Where is this code coming from? Why don't you use the code I gave you? |
Darren76
Posts: 39
|
Posted 10:22 Sep 10, 2016 |
This is just a practice code for myself. Trying to figure out how nodejs cmd works. That's why I am confused and asked for help. Is it different syntax for node ? |
msargent
Posts: 519
|
Posted 10:27 Sep 10, 2016 |
It's a totally different thing. You can't run browser specific code like prompt() on Node. Only browsers understand it. Last edited by msargent at
10:28 Sep 10, 2016.
|