We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Includes

Checking whether a value exists in an array is really easy in JavaScript, just use the .includes() method.

fruits = ["apple", "orange", "banana"];
console.log(fruits.includes("orange"));
// Prints: true
console.log(fruits.includes("pear"));
// Prints: false

Array .includes() checks exact elements; string .includes() checks substrings:

const str = "Hello, world!";
console.log(str.includes("world"));
// Prints: true
console.log(str.includes("banana"));
// Prints: false

Assignment

Let's update Textio's profanity detection to make it a little more robust. Rather than just marking a review as "clean" or "not clean" we need to give it a ranking, which we'll represent as one of 3 strings:

  • clean: No bad words
  • dirty: 1 bad word
  • filthy: 2 or more different bad words

The bad words are:

  • "dang"
  • "shoot"
  • "heck"

Complete the getCleanRank function. It takes an array of words, reviewWords. Check if reviewWords includes the bad words, then return the appropriate ranking. If a word contains special characters (like "d@ng"), it should fool our naive algorithm for now.