diff --git a/Algorithms/Javascript/checkPalindrome.js b/Algorithms/Javascript/checkPalindrome.js new file mode 100644 index 00000000..7a59095c --- /dev/null +++ b/Algorithms/Javascript/checkPalindrome.js @@ -0,0 +1,17 @@ +// program to check if the string is palindrome or not + +function checkPalindrome(str) { + + // find the length of a string + const len = string.length; + + // loop through half of the string + for (let i = 0; i < len / 2; i++) { + + // check if first and last string are same + if (string[i] !== string[len - 1 - i]) { + return 'It is not a palindrome'; + } + } + return 'It is a palindrome'; +}