Tell us what’s happening:
Describe your issue in detail here.
**Your code so far**
function palindrome(str) {
//remove spaces
var stripped = str.replace(/[\d\W_]/g, '');
var str1 = stripped.toLowerCase().split(" ");
var str_concat = "";
for(let i = 0; i < str1.length; i++){
str_concat+= str1[i];
}
var arr = str_concat.split("");
var revArr = str_concat.split("");
revArr.reverse();
var f = 0;
if (arr.length == revArr.length)
{
for(let i = 0; i < arr.length; i++){
if( arr[i] != revArr[i]){
f +=1;
}
}
}
if(f > 0){
return false;
}
else{
return true;
}
}
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.71 Safari/537.36
Challenge: Palindrome Checker
Link to the challenge:
It looks like you accidentally submitted your post before you were done. Can you please tell us what’s going on?
the code is saying that i need eye for an eye to return false how do i do that i am getting confused
ilenia
4
Please do not open multiple topics for the same question
“eye for an eye” is not a palindrome. Once we remove the spaces, it becomes “eyeforaneye”. The reverse of that is “eyenarofeye”, which is different.
Tell us what’s happening:
Describe your issue in detail here.
**Your code so far**
function palindrome(str) {
//remove spaces
var stripped = str.replace(/[\d\W_]/g, '');
var str1 = stripped.toLowerCase().split(" ");
var str_concat = "";
for(let i = 0; i < str1.length; i++){
str_concat+= str1[i];
}
var arr = str_concat.split("");
var revArr = str_concat.split("");
revArr.reverse();
var f = 0;
if (arr.length == revArr.length)
{
for(let i = 0; i < arr.length; i++){
if( arr[i] != revArr[i]){
f +=1;
}
}
}
if(f > 0){
return false;
}
else{
return true;
}
}
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.71 Safari/537.36
Challenge: Palindrome Checker
Link to the challenge:
ilenia
7
Is that what you are doing here, removing spaces?
system
Closed
8
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.