-1

So I want to take in a string, and test for a series of possible words that might be contained in that string, and if any of those words do occur in the string, i want to replace those with a specific word, in this case "is".

function replace_is (string) {
    var exps = [/looks/, /appears/, /seems/, /feels/];
    for(i = 0;i<exps.length;i++) {
        if (string.search(exps[i])==-1) {
            continue;
        }
        else {
            string.replace(exps[i], "is")
            return string;
        }
    }
    return false;
}

Problem is, this does not work. What is a better way to do this? Or why might this not be working?

0

1 Answer 1

1

I don't believe string.replace modifies string, so, you should just:

return string.replace(exps[i], "is");
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.