Tell us what’s happening:
I don’t know why this code is not working. In 'Visual Studio Code", it works perfectly… Can someone help me?
Your code so far
function checkPalindrome(string) {
string = string.replace(/[\W_]/gi, '').toLowerCase();
const len = string.length;
for (let i = 0; i < len / 2; i++) {
if (string[i] !== string[len - 1 - i]) {
return false;
}
}
return true;
}
// call the function
checkPalindrome("rAcE!?@ cAr!!!");
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36
Challenge: JavaScript Algorithms and Data Structures Projects - Palindrome Checker
Hi there. If you go to the assignment and look at tests it will run, it is calling the function with the name palindrome().
For example…
Waiting:palindrome("A man, a plan, a canal. Panama") should return true.
Your function is called checkPalindrome(). If you change the name of your function to palindrome() the tests will be able to run correctly.
Also i would remove your last line which is a call to checkPalindrome() Bc the tests are very specific.