6 Error Error


I dont understand when I put a movie that already exists I get mesage from 'if' like the movie dont exist.

movies = {
    "Snach" => 5,
    "star wars" => 5,
puts "What do you wist to do (add,)?"
choice = gets.chomp
case choice
when "add"
    puts "What movie title you want to add?"
    title = gets.chomp
    if movies[title.to_sym].nil?
        puts "What rating you give for this movie? (0 - 5)"
        rating = gets.chomp
        movies[title.to_sym] = rating.to_i
        puts "Movie #{title} with a rating #{rating} is added to list"
        puts "Movie already exists in list"
when "update"
puts "Update!"
when "display"
puts "Movies!"
when "delete"
puts "Deleted!"
    puts "Error!"


Remove the last comma in the movies hash.


I done that but still is the same problem


Should be:

choice = case


No, this isn't true. Its

case choice

even in the initial example. In fact choice = case returns an error.


Did you figure this out? I'm having the same problem


Haha... Okayy!

Do me a favour, please post your code and error! :slight_smile:


Also, as to looking at the initial, as a mirror, you're not wrong but what you will be wrong about is that, this is a set of exercises to BUILD the initial and so...

Please post your well formatted code so I see why my suggested code might not be working for you. :slight_smile:


The reason why is not working to you, it is because there is a mistake in the example.

if movie[title.to_sym] . nil =? (dot)

When it should be

if movie[title.to_sym] = nil =? (equal)

What we are doing is evaluating the "new title" in the current movie hash.
If the "new title" already exist, them it would have a value associated, which means the result will be different of nil.
If it is a new key, when we evaluate it the result would be nil and we can continue adding the new entrance.



but code that asks if it is nil is "nil_variable.nil?" with a dot. It literally says so in the tutorial.
one = sign means assign, where == mean compare. At least that is what i learned so far, correct me if i am wrong :slight_smile:

As for the answer. It is because tutorial confused us all XD

Initially it told us to create a hash and gave us the old way as an example --- "key" => Value
But, now it asked us to compare it to a SYMBOL (variable.to_sym)

So the solution is to correctly make the hash on the start with semicolons (" : ")

movies = {
Snach: 5,
star wars: 5

Now it compares symbols to symbols. Also remember not to use spaces with symbols :wink:

Or, could compare like so if movies[title].nil? and make it a symbol after that :wink: