7 Update


#1
movies = {
    movie1: 1,
    movie2: 2,
    movie3: 3
}

puts "What would like to do?"
choice = gets.chomp.downcase

case choice
when "add"
    puts "Enter a name"
    title = gets.chomp
    if movies[title.intern].nil?
        puts "Enter a rating"
        rating = gets.chomp.to_i
        movies [title.intern] = rating
        puts "#{title} has been added with rating of #{rating}"
else
    puts "That movie already exists! Its rating is #{movies[title.intern]}."
end
    
when "update"
    puts "Enter a name"
    title = gets.chomp
    if movies[title.intern].nil
        puts "Enter a rating"
        rating = gets.chomp.to_i
        movies [title] = rating
        puts "#{title} has been added with rating of #{rating}"
else
    puts "That movie does not exists!"
end

when "display"
    puts "Movies!"
when "delete"
    puts "Deleted!"
else
    puts "Error!"
end

So my question specifically is why I cannot use if movies[title].nil to return false and continue with the code?


#2

This post was flagged by the community and is temporarily hidden.


#3

@khanh.le Of course. Thanks.