Hi,
I wonder what I should change to get my code right. Something is right, but something is still wrong also.
function palindrome(str) {
// Good luck!
str = (str.toLowerCase());
console.log(str);
console.log(str.replace(/\W/g, ''));
return true;
}
palindrome("eye");
You are not checking anything? You return true
in all cases.
I am really stuck with this.
If the reversed version of string is the same as the original one - it’s a palindrome.
In order to complete this challenge you have to do several things:
- Understand what a palindrome is. This is a string that reads the same starting from both sides.
eye, madam, and kayak are palindromes.
- You have to find out how to reverse a string
- Finally, you have to check whether the reversed string equals the original input. Depending upon the result, return a boolean.
You might want to read about String.prototype.split(), Array.prototype.reverse(), Array.prototype.join()
Summary
function isPalindrome (str) {
return str===str.split('').reverse().join('');
1 Like