Day 80: Replace Characters of a String of 100DaysCodingChallenge

Hello all, 

#day80 

Day80 

Today's task was to Write a program to change every letter in a given string with the letter following it in the alphabet entered string by the user.
(ie. a becomes b, p becomes q, z becomes a).
Example:
Sample Input: Abcdef
Sample Output: Bcdefg


I have started the 100 days of coding challenge to improve my programming skills..

Code : 

//function string_reverse(str) 
var newString = prompt("Enter a String : ");
function LetterChanges(text) {
  //https://goo.gl/R8gn7u
  var s = text.split('');
  for (var i = 0; i < s.length; i++) {
    // Caesar cipher
    switch (s[i]) {
      case ' ':
        break;
      case 'z':
        s[i] = 'a';
        break;
      case 'Z':
        s[i] = 'A';
        break;
      default:
        s[i] = String.fromCharCode(1 + s[i].charCodeAt(0));
    }

    // Upper-case vowels
    switch (s[i]) {
      case 'a': case 'e': case 'i': case 'o': case 'u':
        s[i] = s[i].toUpperCase();
    }
  }
  return s.join('');
}
//console.log(LetterChanges("PYTHON"));
//console.log(LetterChanges("W3R"));
//console.log(LetterChanges("php"));
console.log(LetterChanges(newString));


//var newString = '';
//var newString = prompt("Enter a String : ");
for (var i = 0; i < newString.length; i++) {
  if (96 < newString.charCodeAt(i) && newString.charCodeAt(i) < 123) {
    newString += String.fromCharCode(newString.charCodeAt(i) + 1);
  }
}
//return str;
//console.log(`The Replaced Character String is ${newString}`);

Output :     

 




Happy Coding:)

Thank you...      

Comments

Popular posts from this blog

Day 55: Pattern using loops of 100DaysCodingChallenge

Day 7: Square or Power Integer Numbers of 100DaysCodingChallenge

Day 45: Pattern using loops of 100DaysCodingChallenge