en.hobingoding.com - Hi coders. Today, we will explore how to create a JavaScript program to check if a given string is palindrome or not. However, don't hesitate to ask any questions through the comment section below. So, let's see how the code works. Enjoy!
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.")
Now that you've seen how the code works, I hope this tutorial has provided a clear understanding about this topic by using JavaScript. With this knowledge, you can explore more programming concepts and create other fascinating programs. Happy coding and keep on learning on your programming journey!
Feel free to share this knowledge with others. See you in the next post!
Newest
Older