From 957d96830b2d5cffaab561345fa03b19e72cf860 Mon Sep 17 00:00:00 2001 From: Soumi Chatterjee <60042960+soumichatterjee@users.noreply.github.com> Date: Fri, 28 Oct 2022 13:34:15 +0530 Subject: [PATCH] Create pal.js --- pal.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 pal.js diff --git a/pal.js b/pal.js new file mode 100644 index 0000000..a43e937 --- /dev/null +++ b/pal.js @@ -0,0 +1,23 @@ +function checkPalindrome(string) { + + // 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);