Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

use

isPalindrome(name)

under the code

about 4 years ago · Juan Pablo Isaza Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda