jeudi 22 août 2019

just change the vowel to the next letter in javascript

First I want to prove whether there is a vowel in the sentence, if there is a vowel is replaced by the next vowel. letters that are not vowels are not replaced but remain output.

The results of the coding that I made became inappropriate.

function changeVocals(str){
    var split = str.split('')
    var vocal = 'aiueo'
    var change = 'bjvfp'
    var a = ''

    for (var i = 0; i < split.length; i++) {
        for (var j = 0; j < vocal.length; j++) {
            if (vocal[j] === split[i]) {
                a = a + change
            } else {
                a = a + split[i]
            }
        }
    }
    return a     
}

console.log(changeVocals('Alexa')); //'Blfxb'

I expect the output of 'Alexa' to be 'Blfxb', but the actual output is the sentence appears to be repetitive.

Actual Output: AAAAAllllleeebjvfpexxxxxbjvfpaaaa

Aucun commentaire:

Enregistrer un commentaire