如何从键盘输入文本并将其存储到变量中? [英] How to take in text input from a keyboard and store it into a variable?
本文介绍了如何从键盘输入文本并将其存储到变量中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一些简单的方法来从键盘读取文本并将其存储到变量中.因此:
I would just like something simple to read text from a keyboard and store it into a variable. So for:
var color = 'blue'
我希望用户从键盘上为颜色提供输入.谢谢!
I would like the user to provide input for the color from the keyboard. Thank you!
推荐答案
如果您不需要异步的东西,我也建议您使用readline-sync模块.
I would suggest the readline-sync module as well if you don't require something asynchronous.
# npm install readline-sync
const readline = require('readline-sync');
let name = readline.question("What is your name?");
console.log("Hi " + name + ", nice to meet you.");
这篇关于如何从键盘输入文本并将其存储到变量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文