Help 4/10


#1

This is the code I used:

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 "Error!"
end

I got: Oops, try again. It looks like you didn't add to the movies hash!

I tried everything and it doesn't work(even look at the Q&A page). Can you tell me the correct code?


#2

This code looks extremely similar to the one used in the first lesson. You're preventing yourself to learn by copy pasting code, especially code that you don't understand completely.

Anyway, is it the exercise that says in the instructions that to_sym and to_i are not necessary? If so, you'll need to follow these instructions.


#3

Yeah, but I tried every Q&A working code for this and this is just the first attempt I have done


#4

Did you try what I proposed in my previous post?


#5

Yes, I didn't use the to_sym and to_i but it still said
Oops, try again. It looks like you didn't add to the movies hash!


#6

Well your code passed the exercise when taking out all to_sym and to_i calls on my side, so either you forgot one somewhere or you're having a technical issue.

Try refreshing the page or deleting the cache of your browser.


#7

case choice
when "add"
puts "What movie do you want to add? "
title = gets.chomp
puts "What's the rating?"
rating = gets.chomp
movies[title] = rating
puts "#{title} has been added with a rating of #{rating}."
end

what am i doing wrong


#8

@arjofocolovi what am i doing wrong ^^^


#9

I know the problem
I have to test it and I didn't.