Hello!
I’m trying to do the code for detecting palindromes, in this challenge
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker
and my code is too similar of the solution 1, but doesn’t work in palindrome("five|_/|four");
function palindrome(str) {
let str1= str.replace(/[\W_]/g, "").toLowerCase();
if (str1 === str1.split("").reverse().join(""));
return true;
}
palindrome("five|_/|four");
Thanks!
jsdisco
December 15, 2020, 10:45am
2
Your function always returns true
, because you do nothing with that if
statement, you just terminate it with a semicolon.
Maybe check again how if
statements are written:
if (condition to check) {
// do stuff
} else {
// do other stuff
}
ilenia
December 15, 2020, 10:49am
3
your lfunction always returns true
or undefined
maybe, instead of being the condition, you could use yourcomparison in a different way
what a silly thing I have left! thanks a lot!
ilenia
December 15, 2020, 11:00am
5
I mean, return str1 === str1...
is also a good way, it’s also more compact
i think so, when it work! Thanks!