JavaScript Algorithms and Data Structures Projects - Caesars Cipher

Tell us what’s happening:
Describe your issue in detail here. Why do I have an error on my last console.log and why is ‘;’ a mistake?

Your code so far

function rot13(str) {
  let decodedResult = "";
  let alphabetStart = "abcdefghijklm".toUpperCase();
  let alphabetEnd = "nopqrstuvwxyz".toUpperCase();

  // console.log(alphabetEnd[4]);

  for (let i = 0; i < str.length; i++) {
    let letterToDecode = str[i];
    if (alphabetStart.indexOf(letterToDecode) >= 0) {
      // console.log(letterToDecode);
      decodedResult += alphabetEnd[alphabetStart.indexOf(letterToDecode)];
    } else if (alphabetEnd.indexOf(letterToDecode) >= 0) {
      // console.log(letterToDecode);
      decodedResult += alphabetStart[alphabetEnd.indexOf(letterToDecode)];
  } else {
    decodedResult += letterToDecode;
  }
  
  return decodedResult;
}

console.log(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/111.0.0.0 Safari/537.36

Challenge: JavaScript Algorithms and Data Structures Projects - Caesars Cipher

Link to the challenge:

You are getting a syntax error which means you have a mistake in your code. I’ll give you a hint: The number of opening and closing curly braces should be the same.

Thank you for your help,

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