[removed] Counting number of vowels in a string

前端 未结 2 1672
再見小時候
再見小時候 2021-01-18 12:49

I am trying to count the number of vowels in a string, but my counter does not seem to be returning more than one. Can someone please tell me what is wrong with my code? Tha

2条回答
  •  [愿得一人]
    2021-01-18 13:35

    You need to also do this. use toLowerCase() also

     var vowelCount = function(str){
      var count = 0;
      for(var i = 0; i < str.length; i++){
        if(str[i].toLowerCase() == 'a' || str[i].toLowerCase() == 'i' || str[i].toLowerCase() == 'o' ||str[i].toLowerCase() == 'e' ||str[i].toLowerCase() == 'u'){
          count+=1;
        }
      }
     return count;
    }
    vowelCount('aide')
    

提交回复
热议问题