JavaScript Algorithms and Data Structures Projects - Caesars Cipher

honestly! i dont know what is wrong with my code. when I console.log the
rot13(“SERR YBIR?”) ) I get the required message and it passes all the tests; however when I go to submit it tells me complete opposite. please help! ’

Describe your issue in detail here.

Your code so far

function rot13(str) {

  let alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  let secretMessage=[];
  const ROT13str= str.split('');

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

   switch(ROT13str[i]) {
    case "?":
    secretMessage.push("?");
    break;

    case "!":
    secretMessage.push("!");
    break;

    case ".":
    secretMessage.push(".");
    break;

  }

  let findIndex=(alpha.indexOf(ROT13str[i])+13);

 if (findIndex==12){
    secretMessage.push(" ");
  }

 else if (findIndex >=26){
    secretMessage.push((alpha[findIndex-=26]));
  }
  else{
    secretMessage.push((alpha[findIndex]));

  };
    
 };

  return secretMessage.join('').toUpperCase();

}

console.log(rot13("SERR YBIR?") );

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0

Challenge: {{challengeTitle}} JavaScript Algorithms and Data Structures Projects - Caesars Cipher

Link to the challenge:

Try wrapping the result printed to console into some delimiting characters, it will make seeing what’s happening easier.

console.log('"' + rot13("SERR YBIR?") + '"');

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