# Find the longest palindrome in a given string

I’m close to solving this but something’s not quite right. Wouldn’t mind a little help if you have the time. Thanks in advance!

``````var longestPalindrome = function(s) {

var array = s.split("");
var p = 1;
var longest = [];

//beginning of for loop
for (let i =0; i<array.length; i++){
console.log(i);

//beginning of case: middle two elements match
if(array[i]==array[i + p]){

while (array[i-p]== array[i+p+1])
{ currArray = array.slice(i-p,i+p+2); p++;    console.log("even");    }  // while the palendrome can still be extended

if (currArray.length > longest){longest = currArray}
p = 1;

}
// end of case: middle two elements match

//beginning of case: odd palendrome of length 3
else if(array[i]!=array[i + p] && array[i-p]==array[i+p]){

while(array[i -p] == array[i+p]){
currArray = array.slice(i-p,i+p+1); p++;  console.log("odd");}

if (currArray.length > longest){longest = currArray}
p = 1;

}
//end of case: odd palendrome of length 3
else { currArray = null;}

}
//end of for loop

return(longest.join(''))
};

longestPalindrome("bcabvbacdcabv");
```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````

Can you give the link of this challenge?