admin管理员组文章数量:1336311
New to Javascript and I'm wondering how to get user input without using HTML but vscode only.
Any easy way of saving user input in a variable? something like:
var name = input("What is your name?");
var name = prompt("What is your name?");
I don't want to use an HTML form but just vscode console.
Thank you!
New to Javascript and I'm wondering how to get user input without using HTML but vscode only.
Any easy way of saving user input in a variable? something like:
var name = input("What is your name?");
var name = prompt("What is your name?");
I don't want to use an HTML form but just vscode console.
Thank you!
Share Improve this question edited Jul 26, 2019 at 19:02 Rastalamm 1,7923 gold badges24 silver badges33 bronze badges asked Jul 26, 2019 at 18:56 AlexxxAlexxx 571 gold badge2 silver badges5 bronze badges 4- 1 @slynagh what??? – epascarello Commented Jul 26, 2019 at 19:08
- What do you mean vscode only? vscode console?? – epascarello Commented Jul 26, 2019 at 19:09
- @epascarello I fully retract my previous statement - I have no idea what myself or the OP is talking about :/ – slynagh Commented Jul 26, 2019 at 20:51
- @slynagh There's a delete link next to your ment. Hover over it to see it, then flag anything referring to it as 'no longer needed'. – Daedalus Commented Jul 27, 2019 at 0:18
1 Answer
Reset to default 2I think what you mean is basically running the script in the console.
Visual Studio Code has very little to do with this - though it does offer a terminal window(docs) for your convenience, I personally always use the linux terminal(docs). But that's up to you.
So, to run javascript on the machine rather than the browser you need to install node.
- step 1: install node here are the docs for that.
Now all you need to do is write your script and then run it.
- step 2: write script
let name = prompt("what is your name");
prompt()
(docs)would get you the name prompt and store the input as the script is running in the terminal. so write your script let's say something like:
nameProgram.js
;
console.log("Wele to this awesome software that can tell you your own name!");
let name = prompt("What is your name?");
console.log(`Your name is ${name}! see how cool!`);
- step 3: run program
open the terminal whichever way you prefer, go to the directory of the script and type in the following mand:
node nameProgram.js
That's it, your script will run.
本文标签: javascriptHow to get user input with vscode (no html)Stack Overflow
版权声明:本文标题:javascript - How to get user input with vscode (no html) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742381110a2464110.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论