Table of Contents
show
Example 18:
Write a JavaScript program to check whether a string is palindrome or not
const prompt = require("prompt-sync")();
let str1 = prompt("Enter a string : ");
let len = str1.length - 1;
let flag = 1;
for (let i = 0; i < len / 2; i++) {
let fc = str1[i];
let bc = str1[len - i];
if (fc != bc) {
flag = 0;
break;
}
}
if (flag == 1) {
console.log(`${str1} is palindrome`);
} else {
console.log(`${str1} is not palindrome`);
}
Output:
Views: 132