Programming Questions

  • Newest
  • Popular Tags
  • Ask A Question
  • Letter Changes
    Hey I have this code and it always outputs correct answers, but it says that none of the cases are passing. I'm wondering what I'm missing?
    function LetterChanges(str) { 
    var alf = "abcdefghijklmnopqrstuvwxza  [email protected]@##$$%%^^&&**(())__--++==~~``";
    var i = 0, j =0,k=0;
    //var reg = /[aeiou]/g;
    var str1 = str.toLowerCase();
    var arr = [];
      while(i < str1.length) {
        arr.push(alf.charAt(alf.indexOf(str1[i])+1));
        i++;
      }
      
    var arr1 = arr.toString().split(",").join("");
    var arr2 = arr1.replace("a","A");
    var arr3 = arr2.replace("e","E");
    var arr4 = arr3.replace("i","I");
    var arr5 = arr4.replace("o","O");
    var arr6 = arr5.replace("u","U");
    
        return arr6;
      };                           
    LetterChanges(readline()); 
    
    davjohnson posted this question on 12/21/13 | javascript, letter, changes
    Answers
  • +
  • 3
  • -
  • Hey, even when you redo the challenge and submit your new code with the global fixes it doesn't work? I just tested your new code out and it seemed to work fine for me.
  • +
  • 1
  • -
  • It turns out my PC had some adware that was minuplating all my answers, I uninstalled the program and the problem was solved.
  • +
  • 1
  • -
  • just to let you guys know, I have modified with global for the regexp on the replace method (see below). But stil the program is not showing any correct outputs
    function LetterChanges(str) {
    var alf = "abcdefghijklmnopqrstuvwxyza  [email protected]@##$$%%^^&&**(())__--++==~~//::[[]]{{}}||\\";
    var i = 0;
    var str1 = str.toLowerCase();
    var arr = [];
      while(i < str1.length) {
        arr.push(alf.charAt(alf.indexOf(str1[i])+1));
        i++;
      }
      
    var arr1 = arr.toString().split(",").join("");
    var arr2 = arr1.replace(/[a]/g,"A");
    var arr3 = arr2.replace(/[e]/g,"E");
    var arr4 = arr3.replace(/[i]/g,"I");
    var arr5 = arr4.replace(/[o]/g,"O");
    var arr6 = arr5.replace(/[u]/g,"U");
        
        return arr6;
      };   
    LetterChanges(readline());  
    
    
    
  • +
  • 0
  • -
  • I had a different solution, but encountered the same problem, all the aswers are correct(even for the ones i didn't pass), but after submitting it shows that my code didn't pass it.
  • +
  • 0
  • -
  • Yea, it's really weird the code works fine for all test cases, but when I submitt it I get all test cases incorrect. Maybe I'll restart my computer. lol...
  • +
  • 0
  • -
  • oh, weird I must have a browser bug... I tried to redo other questions and they're not working either
  • +
  • 0
  • -
  • Could it possible be line 7. Your while condition is (i < str1.length). This would force an off-by-one extra push command. Generally when doing these array loops i = 0 and i < (str.length -1). I think maybe you're pushing some extra whitespace into your output.
    Log in to write an answer.