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

243
Visualizações
Undefined Value in the end despite using return in function(Javascript)

I am trying to write a function to solve caeser cipher. I have already written the program in python and the answer I got seemed right. But when I tried to convert the algorithm to javascript, the value returned by the function always has "undefined" in the end(despite adding a return command to the function). I have looked through similar problems listed in stack overflow, but none seemed to match my own. Any help will be greatly appreciated. Thanks in advance.

const alphabet = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
function rot13(str) {
    var ans = ""
    for (let i=0; i<=str.length; i++){
        if (alphabet.includes(str[i])){
        if (alphabet.indexOf(str[i])<alphabet.length/2){
            ans += alphabet[alphabet.indexOf(str[i]) + 13]
        } else{
            ans += alphabet[13 - (alphabet.length - alphabet.indexOf(str[i]))]}
        } else{
            ans += str[i]
        }
    }
    return ans
}

about 4 years ago · Juan Pablo Isaza
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