我制作了一个函数,用于从我也制作的变量中删除某个单词。
var eliminateWord = function (usedwords){word2.replace (/go/g," ");
但我似乎无法在这段代码中使用该函数:
var word1 = "go",
word2 = "go to the shops everyday and buy chocolate.";
var eliminateWord = function (usedwords){
word2.replace (/go/g," ");
};
if (word2.match("go")) {
console.log("user entered go");
eliminateWord ();
}
if (word2.match("to")) {
console.log("user entered to");
}
if (word2.match("the")) {
console.log("user entered the");
}
if (word2.match("and")) {
console.log("user entered and");
}
console.log(word2);