All Aboard the Hash Rocket! Trailing comma in example?


#1

Why the trailing comma when creating the numbers hash in the example?

numbers = {
  :one => 1,
  :two => "two",
  :three => 3,
}

Shouldn't it read:

numbers = {
  :one => 1,
  :two => "two",
  :three => 3
}

#2

It's not an error :smile: This is simply a matter of code-style and preference. It can read both ways.


#3

the correct answer is
movies = Hash.new = {
:movie1 => 1,
:drácula => 2,
:matrix => 3
}


#4

If you use the one above you get this message.
Oops, try again. It looks like 1 isn't a string.

This passes though. The instructions ask for a description, not a value

movies = {
:hangover => "good",
:drácula => "eh",
:matrix => "best"
}


#5

I'm really not understanding why this code doesn't work:

movies = Hash.new {
:jaws => "Crazy sharks out to kill you",
:seven => "Serial Killers film with Morgan Freeman",
}
end

It keeps saying:

Oops, try again. Did you create a variable called movies?

YES I DID.


#6

Ok, eventually I went with:

movies = {

:jaws => "Crazy sharks out to kill you",
:seven => "Serial Killers film with Morgan Freeman",
:tron => "Scifi film about going into the grid"

}

But can someone explain why I can't use

movies = Hash.new

If there are two ways of creating hashes, why can't that work?


#7

Hi there, You should use the new version of hash...I have the same problem.