JavaScript Algorithms and Data Structures Projects - Caesars Cipher

Tell us what’s happening:
Describe your issue in detail here.
I have tried my code on the editor many times and it doesn’t seem to work. I tried to troubleshoot it with console.log but it returns, what seems to me, the correct solution. Could someone please tell me what is the problem?

  **Your code so far**
function rot13(str) {
var ans = '';
function de_code(boi) {
  let num = 13;
  boi.toUpperCase();
  const theAlphabet = 'abcdefghijklmnopqrstuvwxyz';
  let index = theAlphabet.toUpperCase().indexOf(boi);
  let index_Num = (index + num)%26;
  if(theAlphabet.toUpperCase().includes(boi)) {
    return theAlphabet.toUpperCase()[index_Num]
  }else {
    return " ";
  }
}
for(let i = 0; i < str.length; i++) {
  console.log(de_code(str[i]))
}

}

rot13("SERR PBQR PNZC");
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36

Challenge: JavaScript Algorithms and Data Structures Projects - Caesars Cipher

Link to the challenge:

1 Like

function rot13(str) {
var endCode = ‘’;
function de_code(boi) {
let num = 13;
boi.toUpperCase();
const theAlphabet = ‘abcdefghijklmnopqrstuvwxyz’;
let index = theAlphabet.toUpperCase().indexOf(boi);
let index_Num = (index + num)%26;
if(theAlphabet.toUpperCase().includes(boi)) {
return theAlphabet.toUpperCase()[index_Num]
}else {
return " ";
}
}
for(let i = 0; i < str.length; i++) {
endCode += de_code(str[i])
}
console.log(endCode);
}

rot13(“SERR PBQR PNZC”);

This is my updated code… Still doesn’t work

your answer seems to be correct but you forget to add all the results back to the string

ans += de_code(str[i])

and there is is another thing its other special characters than space
like ! in the second test

You have to use return statement
return endCode

Thanks for the suggestion

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