我正在尝试获取一些代码,以便根据他们对问题给出的答案在屏幕上显示特定的消息。这是一个使用 Inquirer 包的 Node 应用程序,每次我运行该 Node 应用程序时,它都会返回“未定义”。
{
type: "checkbox",
name: "channels",
message: "Which of these TV channels would you watch?!",
choices: ["Investigation Discovery", "CNN", "Fox News", "TLC"]
}
]).then(function (responses) {
for(let i = 0; i < responses.channels; i++) {
if (responses.channels === 0) {
console.log("You are probably smart");
}`enter code here`
else if (responses.channels === 1) {
console.log("You are probably well informed");
}
else if (responses.channels === 2) {
console.log("You are probably not very well informed");
}
else {
console.log("You are probably an idiot");
}
}
如前所述,它应该根据选择的选项在控制台中返回一条消息,但它只会返回“未定义”。
最佳答案
好的,我自己解决了。这是我需要做的:
if (responses.channels = 1) {
console.log("You are probably smart");
}
else if (responses.channels = 2) {
console.log("You are probably well informed");
}
else if (responses.channels = 3) {
console.log("You are probably not very well informed");
}
else {
console.log("You are probably an idiot");
}
关于javascript - 如何使用 Inquirer 使我的 "if else"语句在此 Node 文件中正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55619992/