I have a problem in Caesars Cipher exercise

Hi!, i wanna share mi code so someone can tell me whats wrong or what can i change, because everything is good except when i console log result , its something like this:
[ ‘f’ ]
[ ‘r’ ]
[ ‘e’ ]
[ ‘e’ ]
[ ‘c’ ]
[ ‘o’ ]
[ ‘d’ ]
[ ‘e’ ]
[ ‘c’ ]
[ ‘a’ ]
[ ‘m’ ]
[ ‘p’ ]

Caesars Cipher

(sorry for my bad english :sweat_smile:)

please post your actual code instead of a screenshot, it’s not easy to debug from a screenshot

function rot13(str) {

  var abecedary = "abcdefghijklmnopqrstuvwxyz";


 var finalString = str.replace(/\s/g, "")


  for (let l = 0; l < str.length;l++){

   let findCharacter = rot13.indexOf(finalString[l])

   var result = abecedary.charAt(findCharacter).split("")






rot13("SERR PBQR PNZC");

Hello alexsrbernic,

Please link your coding challenge, so we can run your code and debug it.

I guess your problem is the .split("") call. abecedary.charAt(findCharacter) should already give you the correct solution.

Also, you can format your code nicely in this forum, here is a comprehensive guide on how to do that:


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Hi gdennci , thanks for the answer!
The problem I have is that I want to concatenate the letters that remain one below the other, and I don’t know how to do it

So charAt is giving you back a string, yes? And you want result to be the final confined string? Can you think of something you’ve learned to add a string onto another string, rather than adding to an array with split()?

Hey alexsrebernic,

I see. So the thing is that split does not help you with that. As the name already suggests, it splits a String on a specific character that you provide. E.g. "foo:bar".split(":") returns an array with the values ["foo", "bar"].

What you want is to concatenate the characters that you found into a new string. Concatenating is just another word for attaching something, in your case to a string.

I’ll give you a hint how you can do that:

(1) Create an empty string e.g. my_result = ""

(2) Concatenate the characters that you found inside the for loop to that String variable. You can use the + operator like so my_result = my_result + "a", or the short version my_result += "a"

I hope this helps you.


1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.