0

我想为某些单词制作一个内容过滤器,然后将这些单词显示在控制台日志中。这是 js Fiddle 链接:http: //jsfiddle.net/Kz42U/4/

var words1 = prompt("Type In Anything");
var words2 = prompt("Type In Anything");
if (words1 == words2){
    alert("Words are Equal");    
}
else {
    alert("Words Are Not Equal");
}
var eliminateWord = function (doubles) {
    if "go" in words1():{
        console.log("user has entered go")
    }
};
4

1 回答 1

0

采用.match

"foo bar mania".match("foo"); // ["foo"]

var word1 = "go",
word2 = "go kart";
var entered = word1.match("word2");
if (entered) {
    console.log("words match");
} else {
    console.log("words don't match"); // output
}
if (word2.match("go")) {
    console.log("user entered go"); // output
}
于 2013-06-08T13:03:00.823 回答