DEV Community

jazmineubanks
jazmineubanks

Posted on

TIL 03/23/23

Today was a very frustrating day as I dived into the EACH module in my Ruby course.

I was stuck on a specific question for quite some time:

Write a program that:

Asks the user to enter a word.

The program should print each letter in the word the number of times it appears in the word.

I realized that I was highly overthinking it. I relied on chat GBT to help explain things to me and the answer it provided still was not passing in the ruby course.
I asked for help and others could not figure it out as well.
I decided to take a break and look at it with fresh eyes on 03/24.
At this point I was still frustrated so, I asked another classmate of mine and WALA!
The answer is below:

puts "Enter a word:"

answer = gets.chomp.split("")

answer.each do |letter|

count = answer.count(letter)
p "#{letter} appears #{count} times"
end

I understand why this was done in this format. I still believe I need more and more practice!

Top comments (0)