制作内容过滤器

时间:2013-06-08 11:04:00

标签: javascript filter

我想为某些单词制作内容过滤器,然后取出单词并在控制台日志中显示它们。 这是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")
    }
};

1 个答案:

答案 0 :(得分: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
}