5. Not My Type -- "Did you call .to_sym on title and .to_i on rating before adding them to the hash?"


#1

I keep getting the error message that I did not properly format the .to_sym and .to_i methods.

What am I doing wrong here?

movies = { forrest_gump: 5,
}
puts "What would you like to do?"
choice = gets.chomp

case choice
when "add"
  puts "What movie would you like to add?"
  title = gets.chomp
  puts "What rating would you give this movie?"
  rating = gets.chomp
  title.to_sym
  rating.to_i
  movies[title] = rating
  puts "#{title} was added!"
end

#2

Make sure you set the new value of title and rating respectively otherwise you are simply ignoring the return value(s) of the functions.

title = title.to_sym, for example.


#3

In an earlier version of my code, I had both methods followed with a "!" which should have permanently changed the variable, but they didn't work.

Your advice worked, thank you. But I think 12. A Night at the Movies needs to be reexamined by the folks at Codecademy. There seems to be a lot of flaws in the code reader.


#4

Yeah, using ! should have worked as well, as far as I know.


#5

Hey there, thought I'd let you know about some information I've found.

Turns out ! and ? do not exist for every method, as they are pieces of the method signature (name).

e.g. def to_sym!: is different than def to_sym:.

Strings in ruby do not have a to_sym! method, but only a to_sym method. That's why you were unable to use the !.

Happy coding.


#6

Please,I do not understand where is my mistake:

movies={
    "hacker"=>4.3,
    "leet"=>4.7,
    "eleet"=>5,
}
puts " Make Your Choise : \n"
choice=gets.chomp
case choice
when "add"
puts "What movie would you like to add?"
title = gets.chomp
title=title.intern
puts "What rating would you give this movie?"
rating = gets.chomp
rating = rating.to_i
movies[title]=rating
puts "#{tit} was added!"
when "update"
puts "Updated!"
when "display"
puts "Movies!"
when "delete"
puts "Deleted!"
else
    puts "Error!"
end

#7

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