Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

137
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

use

isPalindrome(name)

under the code

about 4 years ago · Juan Pablo Isaza Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda