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

For...of Loops

JavaScript has a relatively new for...of syntax to loop over a sequence without the need to keep track of the index manually. So, instead of typing out all of this:

let woods = ["oak", "pine", "maple"];
for (let i = 0; i < woods.length; i++) {
  console.log(woods[i]);
}
// prints:
// oak
// pine
// maple

We can write this:

let woods = ["oak", "pine", "maple"];
for (let wood of woods) {
  console.log(wood);
}
// prints:
// oak
// pine
// maple

It's a lot like Python's for...in syntax, but be careful not to confuse it with JavaScript's for...in syntax, which is used to loop over the keys of an object. This one has bitten me on many a tired coding session.

Assignment

Textio still has a profanity problem... who knew people on the internet could be so crass???

Complete the getCleanMessages function. It should return a new array containing only the "clean" messages - messages that don't contain the bad word. It accepts:

  • messages: an array of strings, where each string is a user message.
  • badWord: a word that should be filtered out.

Be sure to make the matching case insensitive.

The toLowerCase() method is very useful here!