Skip to content Skip to sidebar Skip to footer

Widget HTML #1

JavaScript Program to Check if a Given String is Palindrome or Not

JavaScript Program to Check if a Given String is Palindrome or Not

Test Case

Test #1
Input String : abcba
abcba is a Palindrome.

Test #2
Input String : abcde
abcba is not a Palindrome.

Source Code

//visit us @hobingoding.com

let palindrome = true
let string = "abcba"
string = string.toLowerCase()
for(i = 0; i < string.length/2; i++){
    if(string[i] != string[string.length-i-1]){
        palindrome = false
        break
    }
}
if(palindrome)
    console.log(string + " is a Palindrome.")
else
    console.log(string + " is not a Palindrome.")
Fandi Presly Simamora
Fandi Presly Simamora Don't think too long because the chance can't waiting for you.

Post a Comment for "JavaScript Program to Check if a Given String is Palindrome or Not"