6. Error ! Error, Can't convert Symbol into Integer


#1



Hello everybody,

I am wohrking on this error for more than 2 hours !
When I " save and submit", after scoring the rating, I have a message "can't convert Symbol into Integer".
And at the same time, I get the message "start next lesson"
I want to understand my mistake before continuing. Thank you in advance for your help.


movies = { alien:  20,
star_treck: 13,
pretty_woman: 17
}
puts "What would you like to do?"
puts "-- Type 'add' to add a movie."
puts "-- Type 'update' to update a movie."
puts "-- Type 'display' to display all movies."
puts "-- Type 'delete' to delete a movie."

choice = gets.chomp

case choice

when "add"
puts "Please write a movie title"
title = gets.chomp
puts " Please write a rating"
rating = gets.chomp
movies = [title.to_sym, rating.to_i]

if movies[title.to_sym].nil?
puts "give a rating please (1 to 20)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} has been added with a rating of #{rating}"
else
    puts "this movie already exists"
end



#2

I realized my mistake. I must remove three lines of code before "if"

'''
puts " Please write a rating"
rating = gets.chomp
movies = [title.to_sym, rating.to_i]
'''
... And sorry for the spelling mistakes in English


#3

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