Build a Word Counter - Step 8

Tell us what’s happening:

I’m trying Step 8. The instructions (and error) say I should create an empty for…of loop that iterates over each word in sentence. I thought that is what my code is doing. Please advise

Your code so far

function printCharacters(str) {
  for (const char of str) {
    console.log(char);
  }
}
printCharacters("hello");

function getMatchedWordCount(sentence, match) {
  let count = 0;

// User Editable Region

  for (const word of sentence) {
    
  };

// User Editable Region

  return count;
}

console.log(
  getMatchedWordCount(
    ["I", "really", "really", "really", "like", "to", "code"],
    "really"
  )
);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:150.0) Gecko/20100101 Firefox/150.0

Challenge Information:

Build a Word Counter - Step 8

Github Link: freeCodeCamp/curriculum/challenges/english/blocks/workshop-word-counter/6921de8d2a111d0341cff702.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @ambradnum

Try writing your code all on one line without the semi-colon to pass the tests.

Happy coding!

Thank you that worked - I tried on one line before but had a semi-colon. Why is the semi-colon wrong?

The curly braces indicate a code block. Semicolons are used after statements but are normally not used after code blocks. For example, if I define a function like this:

function myFunc() {}

there is no semi-colon after the code block containing the function’s code.

Thank you - all makes sense now :slightly_smiling_face: