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

244
Vistas
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 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