レッスンに戻る

スパムをチェック

重要度: 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") );

サンドボックスでテストを含むソリューションを開きます。