Kind of lost in "Cesar's Cipher" challenge

Can you guys point me in the right direction for the “Caesar’s Cipher” challenge? I’ve managed to turn the string into an array of numbers matching the letters and then subtracting 13 from all those array numbers but, I can’t figure out how to turn those numbers into letters again or how I’m going to join them correctly to fit the original sentence structure here’s what I’ve got so far…:

function rot13(str) { // LBH QVQ VG!
var newStr = "";
for (var i = 0; i < str.length; i++) {
newStr += str.charCodeAt(i) + ',';
}
var newStrSplit = newStr.split(",").map(function(val){
return val -13;
});
newStrSplit.pop();
return newStrSplit;
}

this returns: [70, 56, 69, 69,…etc.] is this even the right way to go about this challenge? Starting to feel like I’m veering off course and there is a better way to solve this. It’s very discouraging been working on this challenge about 7 hours now and feel I’m nowhere even close to completing it. How do beginners do this? Just feel completely hopeless and lost on some of these challenges…

You don’t need to do that. Turning it into array of letters will be simpler to work with.

See String.fromCharCode()

If they stayed as array of characters, you can just do a quick .join(‘’) to turn it back into string.

1 Like

Hello there!

To address your first issue of not being able to turn numbers into letters again—the hint is actually given in the description of the challenge

Here are some helpful links:

String.prototype.charCodeAt()
String.fromCharCode()

There is another problem with the code, but I won’t spoil that for you because you will likely realise what the issue is once you will have tried fromCharCode().

As for being discouraged, my personal advice for algorithm-related challenges/problems is to come to the forums or pop into the chat for a hint. In these cases, I find that not asking for help for too long, provided that you have tried what is available to you at that moment, is counter-productive. While it’s great to figure things out yourself, your goal right now is, most likely, to learn how to program and get things working instead of coming up with the greatest algorithm—there will be a time for that later when you will have learned a lot more about how to program.

1 Like

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.