robert0
robert0

Reputation: 445

If string doesn't contain, then x, else y

I have this code, which checks if the string contains certain words, then return blank message:

if(containsWords(['http', 'https'], message)) message = '';

Basically I'm looking for a similar line of code, except I want to filter out messages if they DOESN'T contain certain words.

So basically, if the string doesn't contain a word 'sony' for example, then it would return a blank message.

If it does, then all the messages with a word 'sony' will go through.

Upvotes: 0

Views: 163

Answers (1)

Tamas Szoke
Tamas Szoke

Reputation: 5542

I think what you need is to negate your function, to do this, simply add ! before the function.

Example

if (!containsWords(['http', 'https'], message)) message = '';

Upvotes: 2

Related Questions