Cannot make Palindrome to run successfully

Tell us what’s happening:
Please can somebody tell me what am I doing wrong here?

  **Your code so far**
function stringWithOnlyAlphanumeric(str) {
//Replace takes regex and a replacemnt string
  return str.replace(/[\W_]/gi, "");
}
console.log(stringWithOnlyAlphanumeric("Hello, world!@# Iam happy to be here !!!!!!"));
function stringLowercased(str) {
return str.toLowerCase();
}

const stringReversed = (str) => { 
let result = "";
for (let i=str.lenght-1; i >= 0; i--) {
  result += str[i];
    }
return result;
}
console.log(stringReversed("Hello"));

function palindrome(str) {
//Remove non-alphanumeric characters
const cleanedUpStr = stringWithOnlyAlphanumeric(str);
//Making string lowercase 
const lowercaseStr = stringLowercased(cleanedUpStr);
//Reverse the String
const reversedStr = stringReversed(lowercaseStr);
//Return the conparison of:
//Reversed string equals to lowercase cleaned up string
console.log(`Is "${lowercaseStr}" equals to "${reversedStr}"?`)
return lowercaseStr == reversedStr;
}
//These are palindromes
//Tenet
//Hannah
//tacocat
console.log(palindrome("eye"));
  **Your browser information:**

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

Challenge: Palindrome Checker

Link to the challenge:

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Typo: its str.length :slight_smile:

Ok so I spent a few minutes modifying your code. Im tempted to provide the answer but I wont.

I suggest assigning result to an array and instead of += , push it into the result array . And return a joined result with toLowerCase(). Im sure this is what you tried to do.

Edit: Nvm, It will work even if you only change lenght to length but the above way works too :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.