スパムをチェック
重要度: 5
str
に「バイアグラ」または「XXX」が含まれている場合はtrue
を返す関数checkSpam(str)
を作成し、それ以外の場合はfalse
を返します。
関数は大文字と小文字を区別しない必要があります
checkSpam('buy ViAgRA now') == true
checkSpam('free xxxxx') == true
checkSpam("innocent rabbit") == false
検索で大文字と小文字を区別しないようにするには、文字列を小文字にしてから検索します
function checkSpam(str) {
let lowerStr = str.toLowerCase();
return lowerStr.includes('viagra') || lowerStr.includes('xxx');
}
alert( checkSpam('buy ViAgRA now') );
alert( checkSpam('free xxxxx') );
alert( checkSpam("innocent rabbit") );