Ad
Code
Diff
  • // Description:
    // Write a function caesar() that will return the input message with each character 
    // shifted to the right n times in the alphabet. Make sure the encoded message is in 
    // all caps since the Romans didn't use lowercase letters. Only punks use lowercase letters.
    
    // Example : 'James is the greatest at kumite!' => 'MDPHV LV WKH JUHDWHVW DW NXPLWH!'
    
    // Make sure to preserve the spaces and punctuation of the original message, you know, for clarity's sake.
    
    
    const caesar = (shift, msg) => {
      let encoded = "";
      msg = msg.toUpperCase();
      
      for(let i = 0; i < msg.length; i++) {
        let charcode = (msg[i].charCodeAt());
        if(charcode > 64 && charcode < 91) {
          charcode += shift;
        } encoded += String.fromCharCode(charcode);
      }
      
      return encoded;
    
    };
    • // Description:
    • // Write a function caesar() that will return the input message with each character
    • // shifted to the right n times in the alphabet. Make sure the encoded message is in
    • // all caps since the Romans didn't use lowercase letters. Only punks use lowercase letters.
    • // Example : 'James is the greatest at kumite!' => 'MDPHV LV WKH JUHDWHVW DW NXPLWH!'
    • // Make sure to preserve the spaces and punctuation of the original message, you know, for clarity's sake.
    • const caesar = (shift, msg) => {
    • let encoded = "";
    • msg = msg.toUpperCase();
    • for(let i = 0; i < msg.length; i++) {
    • let charcode = (msg[i].charCodeAt());
    • if(charcode > 64 && charcode < 91) {
    • charcode += shift;
    • } encoded += String.fromCharCode(charcode);
    • }
    • return encoded;
    • };