My code doesnt work

I am confused why my code doesn’t work. Please help!

let betterWords = ;
for (let i = 0; i < storyWords.length; i++) {
for (let j = 0; j < unnecessaryWords.length; j++) {
if (storyWords[i] !== unnecessaryWords[j]) {

There is an array of words that are unnecessary. Iterate over your array to filter out these words. Save the remaining words in an array called betterWords . There are several ways that you could achieve this.


Let’s assume storyWords[i] is ‘whatever’ and that is in the array unnecessaryWords. But it is the second item in the array unnecessaryWords. Now let’s assume the first item in unnecessaryWords is ‘extremely’.
Then your condition for the the first iteration of for (let j = 0; j < unnecessaryWords.length; j++) is a hit already:

if ('whatever' !== 'extremely') { // true
 betterWords.push('whatever'); // will be pushed although in array unnecessaryWords

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.