Programming with JavaScript

⌘K
  1. Home
  2. Docs
  3. Programming with JavaScri...
  4. Example Programs
  5. Palindrome Number

Palindrome Number

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:

Loading

Views: 132

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments