14. Multidimensional Arrays. Code looks ok and works, but course wont let me go further


#1




The code looks ok and it works, but the course page shows this message and I can't finish exercise. Whats wrong?
Error message: Oops, try again. It looks like my_array isn't an array.


my_array = {
    "joey" => "tribiani",
    "rachel" => "green",
    "monica" => "geller"
}

my_array.each do |name, surname| 
    puts "#{name}: #{surname}"
end


#2

an array is inside of bracket notation...
did you read the hint?
This is an example of what it should look like:

array = [[thing, thing], [thing, thing]]

#3

I tried to write it this way - didn't work at all. And, as I understand, it's possible to write it two ways. This is the example from the course:
secret_identities = {
"The Batman" => "Bruce Wayne",
"Superman" => "Clark Kent",
"Wonder Woman" => "Diana Prince",
"Freakazoid" => "Dexter Douglas"
}
secret_identities.each do |character, person|
puts "#{character}: #{person}"
end

"bracket notation" way:
my_array = [[joey, tribiani], [rachel, green], [monica, geller]]

my_array.each do |name, surname|
puts "#{name}: #{surname}"
end

compilator message: undefined local variable or method `joey' for #
And "Oops, try again. It looks like my_array isn't an array"


#4

Those create different data structures:

puts [].class  # Array
puts {}.class  # Hash

Have a look at ruby's error message, it mentions using an undefined name


#5

Oh, I got it. Stupid mistake:) Thanks:)


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.