From bbb6db9580eac2bf24d54842e9ba12f5c83397ac Mon Sep 17 00:00:00 2001 From: prema464 <92637785+prema464@users.noreply.github.com> Date: Sun, 17 Oct 2021 09:37:57 +0530 Subject: [PATCH] Add files via upload --- palindromes.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 palindromes.txt diff --git a/palindromes.txt b/palindromes.txt new file mode 100644 index 0000000..7ad7a74 --- /dev/null +++ b/palindromes.txt @@ -0,0 +1,25 @@ +// 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'; +} + +// take input +const string = prompt('Enter a string: '); + +// call the function +const value = checkPalindrome(string); + +console.log(value); \ No newline at end of file