Build a Proofreading Tool - Step 2

Tell us what’s happening:

Step 2 is saying … “ReferenceError: word is not defined”

I’m able to find an alternative code approach that works, but I still can’t understand why this approach is causing this error to be thrown.

Your code so far

function isPalindrome(word) {
  let wordLowerCase = word.toLowerCase();
  let wordLowerCaseReverse = wordLowerCase.split('').reverse().join('');
  if (wordLowerCase == wordLowerCaseReverse) {
    return true;
  } else {
    return false;
  };
};

let words1 = ["one", "two", "level", "three", "racecar"]
let words2 = [];

function findPalindromeBreaks(words) {
  let palindromeBreaks = [];
    for (word of words) {
      let indice = 0;
      if (isPalindrome(word) == true) {
        indice++;
      } else {
        palindromeBreaks.push(indice);
        indice++;
      }
      return palindromeBreaks;
    }
};

console.log(findPalindromeBreaks(words1));
console.log(findPalindromeBreaks(words2));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36

Challenge Information:

Build a Proofreading Tool - Build a Proofreading Tool

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-proofreading-tool/69dd63d1dcdeccb7b39ba4c3.md at main · freeCodeCamp/freeCodeCamp · GitHub

even in loops you need to use the let or const keyword to define variables

Hi @snaylspace,

The syntax of your for loop in incorrect.

for…of - JavaScript | MDN

Happy coding

Thank you! :slight_smile: This resolved the glitch I was experiencing.