[SOLVED] Caesars Cipher ignoring marks and spaces

[SOLVED] Caesars Cipher ignoring marks and spaces
0

#1

I got a problem with this challenge. This code seems to not recognizing a question mark ( 63 ) or a exclamation mark ( 43 ) . I had the same issue with a space ( 32 ). For that I set up a else if statement just for that case, otherwise the code is ignoring spaces as well. What did I wrong and even with my third else if statement why is it ignoring all marks and sapces?

thank you very much in advance. Im going nuts because I cant figure it out right now…

Your code so far

function rot13(str) { // LBH QVQ VG!

  var newArr = []; 
  
  // loop through str, convert to array with numbers
  for (var i = 0; i < str.length; i++) {
    var cc = str.charCodeAt(i);
    
    if ( cc >= 65 && cc <= 77 ) 
      {
        newArr.push( cc + 13);
      }
    else if ( cc >= 78 && cc <= 90 )
      {
        newArr.push( cc -13 );
      }
    else if ( cc > 90 && cc < 65 )
      {
        newArr.push( cc );
      }
    else if ( cc == 32 )
      {
        newArr.push( cc );
      }

   
    
  }
  
  var toString = String.fromCharCode.apply(null, newArr);
  return toString;
}



// Change the inputs below to test
rot13("! ? . SERR");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0.

Link to the challenge:


#2

Have you solved this yet? This condition is odd:

cc > 90 && cc < 65

There’s no way for a char code to be both below 65 and above 90. Maybe you meant the || operator? This also makes the last else-if block redundant.


#3

yes I meant || . But I solved it 5 minutes ago anyway!

Thank you for your reply :slight_smile: