Step-by-step solution 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 cjordanball 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 EmperorDuny Challenge Score: 10 Python
5 gzamfire Challenge Score: 10 Python
6 mmalkavian Challenge Score: 10 Python
2 GarenLiang Challenge Score: 10 JavaScript
3 beeboop19 Challenge Score: 10 JavaScript
2 lokeshmogra Challenge Score: 10 Cpp
3 cdms0 Challenge Score: 10 Cpp
4 gutty333 Challenge Score: 10 Cpp
4 jackgeek Challenge Score: 10 JavaScript
7 hurgadion Challenge Score: 10 Python
8 scates Challenge Score: 10 Python
9 ricky0309 Challenge Score: 10 Python
3 Bohdan Challenge Score: 10 Ruby
5 chrigolex Challenge Score: 10 JavaScript
10 philtroin Challenge Score: 10 Python
5 sanguookchoi Challenge Score: 10 Cpp
6 mattlarsh Challenge Score: 10 JavaScript
7 zestybmac Challenge Score: 10 JavaScript
4 SSJ6Porfy Challenge Score: 10 Ruby
8 deuzen Challenge Score: 10 JavaScript
1 arjnklc Challenge Score: 10 Java
9 SuprDewd Challenge Score: 10 JavaScript
5 gladysum Challenge Score: 10 Ruby
10 safetyscissors Challenge Score: 10 JavaScript
6 theBestFella Challenge Score: 10 Cpp
6 toasterbob Challenge Score: 10 Ruby
7 duncanbb Challenge Score: 10 Ruby
8 youngheekwon Challenge Score: 10 Ruby
9 kmosier Challenge Score: 10 Ruby
10 kelaiyarao1 Challenge Score: 9 Ruby
7 johne Challenge Score: 10 Cpp
1 ionutforyou Challenge Score: 10 PHP
8 Justification Challenge Score: 10 Cpp
2 tostercx Challenge Score: 10 PHP
9 Zeikar Challenge Score: 10 Cpp
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
10 anta0 Challenge Score: 10 Cpp
7 nicklivens Challenge Score: 10 Java
8 KSmithson Challenge Score: 10 Java
3 longcheng Challenge Score: 10 PHP
9 Redmanter Challenge Score: 10 Java
4 torbjornperttu Challenge Score: 10 PHP
5 albionselimaj Challenge Score: 10 PHP
10 zawiczek Challenge Score: 10 Java
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 challengs, 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 got my App Academy acceptance yesterday, and Coderbyte was definitely a huge help.” ― Tomer
  • 200+ Coding Challenges
  • Mock Interview Questions
  • 500,000+ Code Solutions
  • Algorithm Tutorials
  • Interview Prep Courses