These are chat archives for Moose1551/JavaProblems

8th
Jun 2016
Zach
@Moose1551
Jun 08 2016 12:04
function rot13(str) { // LBH QVQ VG!

  var answer = str.split("");

for (var i = 0; i < str.length; i++) {
  switch (str[i]) {
    case "A": answer = "N";
      break;
    case "B": answer = "O";
      break;
    case "C": answer = "P";
      break;
    case "D": answer = "Q";
      break;
    case "E": answer = "R";
      break;
    case "F": answer = "S";
      break;
    case "G": answer = "T";
      break;
    case "H": answer = "U";
      break;
    case "I": answer = "V";
      break;
    case "J": answer = "W";
      break;
    case "K": answer = "X";
      break;
    case "L": answer = "Y";
      break;
    case "M": answer = "Z";
      break;
    case "N": answer = "A";
      break;
    case "O": answer = "B";
      break;
    case "P": answer = "C";
      break;
    case "Q": answer = "D";
      break;
    case "R": answer = "E";
      break;
    case "S": answer = "F";
      break;
    case "T": answer = "G";
      break;
    case "U": answer = "H";
      break;
    case "V": answer = "I";
      break;
    case "W": answer = "J";
      break;
    case "X": answer = "K";
      break;
    case "Y": answer = "L";
      break;
    case "Z": answer = "M";
      break;
  } return answer;  
}
  }   


// Change the inputs below to test
rot13("SERR PBQR PNZC");
Zach
@Moose1551
Jun 08 2016 12:26
@Moose1551 you first check is the char code is > 64 and < 91. That’s A-Z. Ignore anything else. Then you add 13. If the character code + 13 would be greater than 90, then something like 64 + (code - 90) would work, else adding 13 is fine
Zach
@Moose1551
Jun 08 2016 12:43
strArr = str.split(‘’)
for(let i = 0; i < strArr.length; i++) {
  strArr[i] = strArr[i].charCodeAt()
}
return strArr
Zach
@Moose1551
Jun 08 2016 13:18
function rot13(str) {
var strArr = str.split('');

  for (var i = 0; i < strArr.length; i++) {
strArr[i] = strArr[i].charCodeAt();

  }return strArr;


}
rot13("SERR PBQR PNZC");