Cesars Cipher Quesiton

Hi im stuck on the cesars cipher problem and not sure how to proceed. I can get the characters to decode but they are in the wrong order. When there are more one letter inputted to the string it add the 2nd character the beginning instead of the end.

function rot13(str) {
  const cipher = {
    'A': 'N',
    'B': 'O',
    'C': 'P',
    'D': 'Q',
    'E': 'R',
    'F': 'S',
    'G': 'T',
    'H': 'U',
    'I': 'V',
    'J': 'W',
    'K': 'X',
    'L': 'Y',
    'M': 'Z',
    'N': 'A',
    'O': 'B',
    'P': 'C',
    'Q': 'D',
    'R': 'E',
    'S': 'F',
    'T': 'G',
    'U': 'H',
    'V': 'I',
    'W': 'J',
    'X': 'K',
     'Y': 'L',
     'Z': 'M'   


let newArr = str.split('')
let testString= []
 for (let [key, value] of Object.entries(cipher)) {
for(let i = 0; i < newArr.length; i++){
 if(newArr[i] == key){
  testString += value




When a return statement executes, the function exits immediately regardless if there are for loops that have not completed.

The fact that you seem to not know this fact tells me you would benefit from going through the entire JavaScript curriculum before working on the certification projects.

I do know this… the code is not complete, when I try to add the values to string such that str = “SERR” it returns “REEF” instead of “FREE”

Then you know why you only get one character.

Not with the code you posted above. rot13("SERR") returns R.

Please check the post I have edited to better explain my problem. I did not mean to say that return was the problem my was problem that it returns in the wrong order and I don’t understand why.

If you have made it this far in the curriculum, then you should know how to write your algorithm out first before writing any code. See if you can describe your algorithm to us, so we can first make sure you are on the right track. Based on the code you have written so far, you do not seem to understand the complete logic (not code) involved to solve the problem.

FYI - the string is not being created in reverse. It may appear that way for some strings, but there definitely is a reason why it is creating the string in a specific order.

No thanks Ill just work it out a different way.

If you can not explain your algorithm, how can you expect to write the code for it? Are you hoping to just get lucky and write the correct code?

I am trying to help you here but you have got to try and explain the logic that you think will solve the problem. Otherwise, like I said before, you seem very lost on your journey to a solution with the code you have written.

You really should give a basic roadmap of your thoughts about how to go about solving this issue. It will help people guide you, and give you decent instructions to follow yourself so you don’t get lost in code.

If you give us a roadmap we can point out where you took a wrong turn. Otherwise you might end up going round and round in a loop more then you need to.