Your code is not correct


#1

I've been testing your code and when i type display after adding a movie i only see those three movies that are originally in it, without movie i added


#2

Err... Please is this a continued discussion?

Post well formatted code and error given.

Thank you!


#3

Sorry for my delayed response, was on vacation... Also thank you for your fast response.
What i want to say is that the final code from exercise 12. A Night at the Movies is not quite doing what it says.

movies = {
Memento: 3,
Primer: 4,
Ishtar: 1
}

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.downcase
case choice
when 'add'
puts "What movie do you want to add?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "What's the rating? (Type a number 0 to 4.)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} has been added with a rating of #{rating}."
else
puts "That movie already exists! Its rating is #{movies[title.to_sym]}."
end
when 'update'
puts "What movie do you want to update?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "Movie not found!"
else
puts "What's the new rating? (Type a number 0 to 4.)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} has been updated with new rating of #{rating}."
end
when 'display'
movies.each do |movie, rating|
puts "#{movie}: #{rating}"
end
when 'delete'
puts "What movie do you want to delete?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "Movie not found!"
else
movies.delete(title.to_sym)
puts "#{title} has been removed."
end
else
puts "Sorry, I didn't understand you."
end

Once again, this is not my code but the code you see on the beginning of the project which i find not correct because the movies that are added to Hash don't quite stay in it...
Tell me if im wrong.
Thanks!


#4

Hello, there seems to be nothing wrong with the movies hash and they really would stay in it. Just in case you're skeptical about the way the movies and corresponding ratings are added, I have done a mix of it below which works. You could try it out.

movies = {
    "Harry_Porter"=> 4,
    "Cinderella"=> 3,
    "Mask"=> 4,
    Awin: 3
}

I hope this helps! :smile: