-3

私も作成した変数から特定の単語を削除するために使用される関数を作成しました。

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);
4

2 に答える 2

1

replace で取得した値を返すだけです。

var eliminateWord = function (usedwords){return word2.replace (/go/g," ");
于 2013-06-14T13:03:19.380 に答える