Learn
Iterators
Iterator Documentation

There are many additional built-in array methods, a complete list of which is on the MDN’s Array iteration methods page.

The documentation for each method contains several sections:

  1. A short definition.
  2. A block with the correct syntax for using the method.
  3. A list of parameters the method accepts or requires.
  4. The return value of the function.
  5. An extended description.
  6. Examples of the method’s use.
  7. Other additional information.

In the instructions below, there are some errors in the code. Use the documentation for a given method to determine the error or fill in a blank to make the code run correctly.

Instructions

1.

In the code editor, there is an array called words. We want to create a new array of interesting words. The first thing we want to do is check if there are words that are fewer than 6 characters long. There is something missing in the words.some() method call. Fix this method so that true is printed to the console.

For more information browse MDN’s documentation on .some() .

2.

The .some() method returned true, which means there are some words in the array that are shorter than six characters. Use the .filter() method to save any words longer than 5 characters to a new variable called interestingWords, declared with const.

We’ve used .filter() in a previous exercise, but, for more information browse MDN’s documentation on .filter() .

3.

In the last line of main.js, there is this code:

// console.log(interestingWords.every(word => ));

Complete the code between the parentheses to check if every element has more than 5 characters.

Make sure to uncomment (delete the // before) the last line of the program before you run the code.

For more information browse MDN’s documentation on .every() .

Folder Icon

Take this course for free

Already have an account?