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!
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
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/