0

Example: Dota is better than league of legends (true).

Counter Strike is better than Fortnite (false)

I couldn't develop the line of reasoning, could you help me? Thanks.

1 Answers1

0

The simplest way is this:

function findDota (string){
    if (string.toLowerCase().search("dota") != -1){
        return true;
    } else{
        return false;
    }
}

string.search() returns the position (0 indexing) of the first occurence of the search parameter in the string. If the search parameter isn't in the string it returns -1.

A more complex answer could use regular expressions (regexs) which can be very powerful.

function findDota (string){
    if (string.search(/dota/i) != -1){
        return true;
    } else{
        return false;
    }
}

here /dota/i searches for the string dota. The i means it is case insensetive.

useful links:

https://www.w3schools.com/jsref/jsref_search.asp

https://www.w3schools.com/js/js_regexp.asp

https://www.w3schools.com/js/js_string_methods.asp

charlie scott
  • 136
  • 1
  • 9