我可以使用布尔值来解决此问题吗?

时间:2018-10-31 13:16:46

标签: javascript

var userInput = prompt();
var alice = String(userInput);
var bob = String(userInput);
if(userInput == alice || bob){

console.log("It is nice to meet you " + userInput);

} else {
    console.log("You are neither alice or bob ");

}

编写一个程序来提示用户输入名称,并且仅当用户是Alice或Bob时才打招呼。

1 个答案:

答案 0 :(得分:0)

这应该对您有用:

    var userInput = prompt();
    var alice = 'alice';
    var bob = 'bob';
    if(userInput == alice || userInput == bob) {
    
    console.log("It is nice to meet you " + userInput);
    
    } else {
        console.log("You are neither alice nor bob");
    
    }