Errors in counter hashes- section

without a default value

dog_breeds = {“corgi”=>“short and sweet”, “labrador”=>“labradorable”}
dog_breeds[“Australian cattle dog”] #=> nil

with a default value

default_cuties =“cutie”)
dog_breeds[“vizsla”] #=> “cutie”

accessing a nonexistent key doesn’t alter the hash

dog_breeds #=> {}

default_cuties is a new variable that is otherwise referenced no where. I am sure I will figure out how to use on my own but this tutorial does not teach it. If you run this code in your terminal you will see that the example code returns nil not cutie as the tutorial says it will.

1 Like

def most_common_vowel(string)
vowels = %w(a e i o u)
counts = # Give the hash a default value of 0

string.each_char do |character|
counts[character] += 1 if vowels.include?(character)

counts.sort_by {|k, v| v}.last.first

Is an answer as given in the lessons on that alpha course: However this does not satisfy the alphabetical order caveat of the problem.

1 Like