Accueil / javascript / 1-js / 05-data-types / 03-string / 2-check-spam / solution.md

solution.md

Pour rendre la recherche insensible à la casse, transformons la chaîne de caractères en minuscule, puis recherchons :

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") );