A night at the movies


#1

hello fellas, I have problem with this exercise, when I type delete and I write Pulp Fiction it doesn't delete it, just says: "Movie not found" and I have simillar problem with other choices


movies = {
    "Pulp Fiction" => 9,
    "Fight Club" => 10,
    "The Usual Suspects" => 9
}

puts "Just write the fucking input biatch!"
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.downcase
case choice
when "add"
    puts "Movie title pls: "
    title = gets.chomp
    if movies[title.to_sym].nil?
    puts "Movie rating pls: "
    rating = gets.chomp
    movies[title.to_sym] = rating.to_i
    else 
        puts "Movie already exists!"
    end
    puts "Movie #{title} with rating #{rating} was added."
when "update"
    puts "Movie title pls: "
    title = gets.chomp
    if movies[title.to_sym].nil?
        puts "Movie not found."
    else 
        puts "Type new rating!"
        rating = gets.chomp
        movies[title.to_sym] = rating.to_i
        puts "#{title}' rating updated."
    end
when "display"
    movies.each do |movie, rating|
        puts "#{movie}: #{rating}"
    end
when "delete"
    puts "Movie title pls."
    title = gets.chomp.to_sym
    if movies[title.to_sym].nil?
        puts "Movie not found"
    else movies.delete(title.to_sym)
        puts "Movie has been deleted."
    end
else 
    puts "Error!"
end

#2

Hi its because you use in the if statemnt .to_sym to the movies title so if your movie inside movies are not symbols it won't see the movies so you can change it from

movies = {
    "Pulp Fiction" => 9,
    "Fight Club" => 10,
    "The Usual Suspects" => 9
}

to

movies = {
    :Pulp_Fiction => 9,
    :Fight_Club => 10,
    :The_Usual_Suspects => 9
}

#3

well, thank you, but this doesn't work as well


#4

can you post your new code?

Edit

I run your code and it work fine

Remenber that if NOW if you wnat to remove Pulp Fiction you will write on the console

Pulp_Fiction

#5

Try this

movies = {
    Pulp_Fiction: 9,
    Fight_Club: 10,
    The_Usual_Suspects: 9
}

Then when prompted to enter movie type in: Pulp_Fiction

Keep in mind that it is case sensitive!


#6

that's why, thank you


#7

I mean i wrote just: "Pulp Fiction"