I have, for the most part, created a recursive solution for the challenge. However, when running the code, there is always an undefined
that is added to the end of the output. Can someone help me figure out why?
**My code so far**
function rot13(str) {
for (let i = 0; i < str.length; i++) {
if (str.length === 0) {
return "";
} else if (str.charAt(i).match(/[^A-Z]/)) {
return str.charAt(i) + rot13(str.substring(i + 1));
} else if (str.charCodeAt(i) < 78) {
return String.fromCharCode(str.charCodeAt(i) + 13) + rot13(str.substring(i + 1));
} else {
return String.fromCharCode(str.charCodeAt(i) - 13) + rot13(str.substring(i + 1));
}
}
}
console.log(rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT."));
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15
Challenge: Caesars Cipher
Link to the challenge: