on-internet
← Community

Count the number of vowels in a text

Stack Overflow ·

A rookie in Ruby here. I'm trying to count the number of each vowel in a text entered by the user but I'm stuck. My code is this at the moment: def count_vowels(phrase) puts 'Enter a text:' phrase = $stdin.gets.downcase.chomp a_count = 0 vowels = ["a", "e", "i", "o", "u"] # these two lines are only for debugging puts "\nThe text is: #{phrase}" puts "#{phrase.chars}" for char in vocals if char == vocals a_count += 1 end return a_count end end count_vowels(ARGV) I don't know how to count each vowel: a = 3 e = 2 and so on.

Comments

Sign in or sign up to comment and upvote.

No comments yet.