Programming Questions

  • Newest
  • Popular Tags
  • Ask Question
  • Letter Changes Problem
    I'm not getting the right answer, a little help would be appreciated! function replace(str) { var newStr = []; var vowels = 'aeiou'; var alpha = [ 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' ]; str = str.split(""); newStr.length = str.length; for(var i = 0; i < alpha.length; i++) { for(var j = 0; j < str.length; j++) { if(alpha[i] === str[j]) { newStr[j] = (alpha[i + 1]); } } } for(var k = 0; k < vowels.length; k++) { for(var x =0; x < newStr.length; x++){ if(vowels[k] === newStr[x]) { newStr[x] = vowels[k].toUpperCase(""); } } } return newStr; } console.log(replace("today is great"));
    CrystalH posted this question on 1/21/14 | javascript, js
    Answers
  • +
  • 0
  • -
  • Have you had a look at other user's code? My solution used an array of vowels and the two String methods fromCharCode() and charCodeAt(): www.w3schools.com/jsref/jsref_obj_string.asp
  • +
  • 0
  • -
  • Hope it can helps =) #include <iostream> #include <string> using namespace std; string LetterChanges(string str) { for (int i = 0; i < str.size(); ++i){ if (isalpha(str[i]) && str[i] != 'z' && str[i] != 'Z'){ str[i] += 1; if (str[i] == 'u' || str[i] == 'e' || str[i] == 'a' || str[i] == 'o' || str[i] == 'i') str[i] = toupper(str[i]); } if (str[i] == 'z' || str[i] == 'Z') str[i] = 'A'; } return str; }
  • +
  • -1
  • -
  • def LetterChanges(word): table = str.maketrans( "abcdefghijklmnopqrstuvwxyz*3", "bcdefghijklmnopqrstuvwxyza*3", ) output = word.translate(table) bowel = "aeiou" n = "" for item in output: if item in bowel: upper = item.upper() n = n + upper else: n = n + item return n print(LetterChanges('fun times!')) # output = gvO Ujnft! why mycode is not accepted?
  • +
  • -1
  • -
  • char[] words = str.toCharArray(); for (int i = 0; i < words.length; i++) if ((words[i] >= 'a' && words[i] <= 'z') || (words[i] >= 'A' && words[i] <= 'Z')) { if (words[i] == 'z' || words[i] == 'Z') words[i] -= 25; else words[i] += 1; if (words[i] == 'a' || words[i] == 'e' || words[i] == 'i' || words[i] == 'o' || words[i] == 'u') words[i] -= 32; } str = new String(words);
    Log in to write an answer.