Hi. What am I doing wrong here?
This code returns palindromes as true…but not non-palindromes as false.
Thanks
function palindrome(str) {
if (str === str.split().reverse().join()) {
return true;
}
return false;
}
palindrome(“eye”);
Hi. What am I doing wrong here?
This code returns palindromes as true…but not non-palindromes as false.
Thanks
function palindrome(str) {
if (str === str.split().reverse().join()) {
return true;
}
return false;
}
palindrome(“eye”);
So close!
Your split()
and join()
methods are missing separators.
Use split("")
and join("")
and it will work. You want to separate each individual letter and then join again.