Vscode-code-runner: Why show the error "prompt is not defined"?

Created on 19 Dec 2016  路  2Comments  路  Source: formulahendry/vscode-code-runner

Dear guys:
I use Visual Studio Code recently, and I found something strange today. When I use the plugin named "Code Runner" to test my code which involves the function "prompt()", the terminal always show the error "prompt is not defined". (Please refer the code)

var names = ["David", "Cynthia", "Raymond", "Clayton", "Jennifer"];
var name = prompt();
var position = names.indexOf(name);
if (position >= 0) {
console.log("Found at position " + position);
} else {
console.log("not found in array.");
}

Please help me to figure out the reason and to find out how to replace "prompt()" by other function?

Thank you so much!

question

Most helpful comment

prompt() is used in browser. The runtime in VS Code is Node.js, you may try http://node.readthedocs.io/en/latest/api/readline/

All 2 comments

prompt() is used in browser. The runtime in VS Code is Node.js, you may try http://node.readthedocs.io/en/latest/api/readline/

I solved this problem using browser instead of NodeJs

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kelo007 picture Kelo007  路  3Comments

rana picture rana  路  5Comments

mjaniec2013 picture mjaniec2013  路  5Comments

nmchgx picture nmchgx  路  3Comments

0x7FFFFFFFFFFFFFFF picture 0x7FFFFFFFFFFFFFFF  路  3Comments