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

242
Views
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
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!