Solutions for Letter Changes
View the challenge

This challenge requires you to change every letter in the string to the letter following it in the alphabet, so a becomes b, z becomes a, etc. Once every letter is changed, we then need to capitalize only the vowels, namely: a, e, i, o, u. We will be changing the letters by using their respective ASCII values and adding 1 to them in order to get the next letter in the alphabet. ASCII values are just numbers that are assigned to each character in a sequential order, for example, the ASCII code for the letter a is 97 and b is 98. What we'll do is convert a letter to its ASCII number, add 1 to it, then convert this new number back into a character using a built-in character function.

function LetterChanges(str) { 

  // we will replace every letter in the string with the letter following it
  // by first getting the charCode number of the letter, adding 1 to it, then 
  // converting this new charCode number to a letter using the fromCharCode function
  // we also check to see if the character is z and if so we simply convert the z to an a
  var converted = str.replace(/[a-z]/gi, function(char) { 
    return (char === 'z' || char === 'Z') ? 'a' : String.fromCharCode(char.charCodeAt() + 1);
  });

  // we have now successfully converted each letter to the letter following it
  // in the alphabet, and all we need to do now is capitalize the vowels
  var capitalized = converted.replace(/a|e|i|o|u/gi, function(vowel) { 
    return vowel.toUpperCase();
  });

  // return the final string
  return capitalized;
         
}
   
LetterChanges("fun times!");                                                      
def LetterChanges(str): 
  
  # our new string with the modified characters
  newString = ""

  # begin by looping through each character in the string
  for char in str:
    
    # check if the current character is an alphabetic character
    if char.isalpha():

      # check if character is z
      if char.lower() == 'z':
        char = 'a'

      # if alphabetic character then add 1 to its ASCII value 
      # by using the built-in ord function then convert back to character
      else:
        char = chr(ord(char) + 1)

    # if new character is a vowel then capitalize it
    if char in 'aeiou':
      char = char.upper()

    # add this modified character to the new string
    newString = newString + char

  return newString
       
print LetterChanges("fun times!")  
def LetterChanges(str)

  # we will replace every letter in the string with the letter following it
  # by first getting the number representation of the letter, adding 1 to it, 
  # then converting this new number to a letter using the chr function
  # we also check to see if the character is z and if so we simply convert the z to an a
  converted = str.gsub(/[a-zA-Z]/) do |c|  
      if c == 'z' or c == 'Z'
        'a'   
      else
        (c.ord + 1).chr
      end
  end
  
  # we have now successfully converted each letter to the letter following it
  # in the alphabet, and all we need to do now is capitalize the vowels
  return converted.tr!('aeiou', 'AEIOU')
         
end
   
# keep this function call here    
puts LetterChanges(STDIN.gets)   
Top User Solutions
1 hyuil Challenge Score: 10 Cpp
1 kalgima Challenge Score: 10 Swift
2 cjordanball Challenge Score: 10 JavaScript
3 hunsoo Challenge Score: 10 JavaScript
1 Qlogin Challenge Score: 10 Python
1 emuchynski Challenge Score: 10 Ruby
2 Sabin Challenge Score: 10 Python
2 junjunparkpark Challenge Score: 10 Ruby
3 Corinto Challenge Score: 10 Python
4 lesian Challenge Score: 10 Python
5 Ryantimjohn Challenge Score: 10 Python
6 EmperorDuny Challenge Score: 10 Python
2 gutty333 Challenge Score: 10 Cpp
4 jrorsini Challenge Score: 10 JavaScript
5 leot75 Challenge Score: 10 JavaScript
3 Ryanm1234 Challenge Score: 10 Ruby
7 gzamfire Challenge Score: 10 Python
6 nulln Challenge Score: 10 JavaScript
8 mmalkavian Challenge Score: 10 Python
7 mattlarsh Challenge Score: 10 JavaScript
8 beeboop19 Challenge Score: 10 JavaScript
3 lokeshmogra Challenge Score: 10 Cpp
4 cdms0 Challenge Score: 10 Cpp
4 rnelson082 Challenge Score: 10 Ruby
9 jackgeek Challenge Score: 10 JavaScript
5 memyselfandhai Challenge Score: 10 Ruby
6 kmosier Challenge Score: 10 Ruby
9 hurgadion Challenge Score: 10 Python
7 lucanioi Challenge Score: 10 Ruby
10 scates Challenge Score: 10 Python
8 Bohdan Challenge Score: 10 Ruby
10 chrigolex Challenge Score: 10 JavaScript
5 sanguookchoi Challenge Score: 10 Cpp
9 SSJ6Porfy Challenge Score: 10 Ruby
10 stevenli Challenge Score: 10 Ruby
1 arjnklc Challenge Score: 10 Java
6 theBestFella Challenge Score: 10 Cpp
7 atib1980 Challenge Score: 10 Cpp
8 terry Challenge Score: 10 Cpp
9 johne Challenge Score: 10 Cpp
1 ionutforyou Challenge Score: 10 PHP
10 Justification Challenge Score: 10 Cpp
2 tostercx Challenge Score: 10 PHP
2 danaksim Challenge Score: 10 Java
3 jakmaj Challenge Score: 10 Java
4 AjeethKannan Challenge Score: 10 Java
5 ph4ntom Challenge Score: 10 Java
6 binfeng Challenge Score: 10 Java
7 nicklivens Challenge Score: 10 Java
8 KSmithson Challenge Score: 10 Java
3 longcheng Challenge Score: 10 PHP
9 Redmanter Challenge Score: 10 Java
10 andyrice2279 Challenge Score: 10 Java
4 torbjornperttu Challenge Score: 10 PHP
5 albionselimaj Challenge Score: 10 PHP
6 teplicko Challenge Score: 10 PHP
7 etybyte Challenge Score: 10 PHP
8 Althalus Challenge Score: 10 PHP
9 smcdowell Challenge Score: 10 PHP
10 jetonr Challenge Score: 10 PHP

Become a Premium Member

With our large collection of challenges, tutorials, and solutions, we make it easy for you to become a better coder, prepare for interviews, and learn new skills from more experienced coders.

“I have my final coding interview with Fullstack Academy tomorrow, and Coderbyte has been an invaluable tool to help me progress as a
developer.” ― Josh Aharonoff
  • 200+ Coding Challenges
  • Mock Interview Questions
  • 700,000+ Code Solutions
  • Algorithm Tutorials
  • Interview Prep Courses