Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
Check if the string is a Palindrome using arrow Functiuons

I want to find if the user entered string is a Palindrome or not using arrow functions. But the code I have written is not showing an output....I dont understand whats wrong pls help....

var name = prompt("Enter Name: ");
const isPalindrome = name => {

  const midPoint = name.length / 2;

  for (let i = 0; i < midPoint && i < name.length; i++) {
    if (name[i] != name[name.length - 1 - i]) {
      console.log(" Not Palindrome");
    }
  }
  console.log("Palindrome");
}

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can check for palindrome without a for loop.

function isPalindrome(string) {
  const toArray = string.replace(/ /g, '').toLowerCase().split('');
  const reverseArray = toArray.slice().reverse();
  const original = toArray.join('');
  const reversed = reverseArray.join('');
  if (original === reversed) {
    return true;
  } else {
    return false;
  };
}
isPalindrome('WORD HERE');
about 4 years ago · Juan Pablo Isaza Report

0

use

isPalindrome(name)

under the code

about 4 years ago · Juan Pablo Isaza Report

0

All you have to do is just to call the function with the user input.

Also remember to return from the function once the input is not found as a palindrome. Else function will log both Not Palindrome and Palindrome when the input is not palindrome

var name = prompt("Enter Name: ");
const isPalindrome = name => {
  const midPoint = name.length / 2;
  for (let i = 0; i < midPoint && i < name.length; i++) {
    if (name[i] != name[name.length - 1 - i]) {
      console.log(" Not Palindrome");
      return;
    }
  }
  console.log("Palindrome");
}
isPalindrome(name);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!