Mini linter project (scope issue?)

Hi

I am kind of stuck in the Mini linter project.
In part 4, I am asked to count overused words. I am able to log the words and quantity of each word to console. See code below. But I want to return the values to use them later in my code, instead of just logging them to console inside my function block. How can I achieve this?

Can I make my function output these values?

//count overused words
let overUsed = () => { //creating function to count overused words

let n = 0; //variable for counting overusedwords

overusedWords.forEach(word => { //iterates through overusedWords
  
n = 0; //resets the counter variable n for each overused word

  betterWords.forEach(words => { //iterates through betterWords

    if (word === words) //checks if word exists in both lists

    n++; //adds one to the counter
     })  

    console.log( `${word}: ${n}`); //logs the word and number to console
})  //tried to "return word" here, but I got an error message.
}

overUsed(); //calling my function, returns this in console: 
//really: 2
//very: 5
//basically: 1

Instead of logging to console, could I store the values in an array for example?

I am completely new to this, and i hope someone can help me.

This might be a case in which an Associative Array (an Object) would be helpful.

You’ll want to assign the value of each word to be n in that object, as shown here.

You can then return the Object you’ve created.

Thanks, but I could not get it to work. :neutral_face: Didn’t quite understand.

However, I found another solution which worked after a bit of trial and error.

I created an empty array (global), and instead of the console.log-statement in my original code, I .pushed the values to the array. :partying_face: