What is wrong with my access hash value


#1



https://www.codecademy.com/en/courses/ruby-beginner-en-F3loB/1/4?curriculum_id=5059f8619189a5000201fbcb#


Error message: (ruby):6: syntax error, unexpected tSTRING_BEG, expecting '}'
"Tomtom" => "cat"
^
(ruby):6: syntax error, unexpected tASSOC, expecting $end
"Tomtom" => "cat"
^


my_hash = Hash.new
pets = Hash.new
pets["moose"] = "dog"

pets = {
    "Moose" => "dog"
    "Tomtom" => "cat"
    "Payzo" => "mini horse"
}

pets.eachdo { |"Moose","dog"| puts "#{dog}"}
pets.eachdo { |"Tomtom","cat"| puts "#{cat}"}
pets.eachdo { |"Payazo","mini horse"| puts "#{mini horse}"}


#2

@csilva09,
After updating my_hash Hash with the =comma-,= separator
with which you separate the =key= =value= pairs from eachother.

pets = {
    "Moose" => "dog",
    "Tomtom" => "cat",
    "Payzo" => "mini horse"
}
pets.each { |key,value|
   puts "#{key} #{value}"
    }

#3

it's still giving me issues.

my_hash = Hash.new
pets = Hash.new
pets["moose"] = "dog"

pets = {
"Moose" => "dog"
"Tomtom" => "cat"
"Payzo" => "mini horse"
}
pets.each { |"Moose","dog"|
puts "#{Moose} #{dog}"
}

ERROR MESSAGE:

(ruby):6: syntax error, unexpected tSTRING_BEG, expecting '}'
"Tomtom" => "cat"
^
(ruby):6: syntax error, unexpected tASSOC, expecting $end
"Tomtom" => "cat"
^


#4

here's the script with the complete key & value but I'm still getting and error message

my_hash = Hash.new
pets = Hash.new
pets["moose"] = "dog"

pets = {
"Moose" => "dog"
"Tomtom" => "cat"
"Payzo" => "mini horse"
}
pets.each { |"Moose","dog"|
puts "#{Moose} #{dog}"
pets.each { |"Tomtom","cat"|
puts "#{Tomtom} #{cat}"
pets.each { |"Payazo","mini horse"|
puts "#{Payazo} #{mini horse}"
}

ERROR MESSAGE
(ruby):6: syntax error, unexpected tSTRING_BEG, expecting '}'
"Tomtom" => "cat"
^
(ruby):6: syntax error, unexpected tASSOC, expecting $end
"Tomtom" => "cat"
^


#6

@csilva09
Please READ
https://discuss.codecademy.com/t/what-is-wrong-with-my-access-hash-value/41478/2?u=leonhard.wettengmx.n


#7

pets.each { |"Moose","dog"|
puts "#{Moose} #{dog}"
}

This part is incorrect. You are not really supposed to write out the actual key and value content, so don't write "Moose", "dog" here.

We use placeholders to represent the key and value. Take note that placeholders are written without quotation marks because they are not strings:

You can literally use the words key and value (no quotation marks), or something that makes sense in context. Try replacing your incorrect section with this:

pets.each { |name,animal|
puts "#{name} #{animal}"
}

you can even use single alphabets like x and y, just like the examples in the lessons. Try using this:

pets.each { |x,y|
puts "#{x} #{y}"
}


#8

pets = {
"Moose" => "dog",
"Tomtom" => "cat",
"Payzo" => "mini horse"
}

pets.each { |x, y| puts "#{x}: #{y}"}

Right way of doing it and You are also forgetting "," commas at the ends of your hash values :slight_smile: