I am new to coding and I am just practicing with some functions and I came across something with the "strict equal" of my conditional.
I am building a simple palindromeChecker in JS.
so I made this:
const w = "Apple";
const palindromeChecker = (phrase) => {
const lowerWord = phrase.toLowerCase().split(" ").join("").split("");
console.log("LowerWord: --->", lowerWord);
const result = lowerWord.join("")
console.log("Result: --->", result);
const reverse = lowerWord.reverse().join("");
console.log("Reverse: --->", reverse);
if (lowerWord.join("") === reverse) {
return true
} else {
return false
}
};
console.log(palindromeChecker(w));
the return keeps coming back true even though the word is clearly not a palindrome. I'm know that I can exchange:
lowerWord.join("")
in the conditional with:
result
and I get the correct answer, but I am wondering why I am getting "true" with lowerWord.join("") when the string is not the same?
thanks in advance!