Tell us what’s happening:
Hy all,
Hope I’m not messing up this first post. I got the palindrome challenge (you can find it at the link below for ease) and the code lower in this message fails to check all challenges. Tested the steps one by one and all should be ok.
Can anyone explain to me why the challenges are not met? And where does that error come from?
Challenges not ok:
// running tests
palindrome(“almostomla”) should return false.
palindrome(“1 eye for of 1 eye.”) should return false.
Cannot read property ‘length’ of null
// tests completed
Your code so far
function palindrome(str)
{
str = str.toLowerCase();
str = str.match(/[A-Za-z]/gi);
for (var i = 0; i<(str.length-(str.length % 2))/2 ; i++)
{
if (str[i] == str[str.length-1-i])
{
return true;
}
else
{
return false
}
}
// Good luck!
}
palindrome("almostomla");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker/