0

在红宝石中,我们可以这样做

print "How old are you? "
age = gets.chomp()
print "How tall are you? "
height = gets.chomp()
print "How much do you weigh? "
weight = gets.chomp()

puts "So, you're #{age} years old, #{height} tall and #{weight} heavy."

它会喜欢这个

在此处输入图像描述

但是如何在nodejs中做到这一点?

4

1 回答 1

9

取自以下的 node.js 文档readline

var readline = require('readline');

var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.question("What do you think of node.js? ", function(answer) {
  console.log("Thank you for your valuable feedback:", answer);

  rl.close();
});
于 2013-06-01T13:18:30.417 回答