Display 8/10 won't work in Ruby


#1

movies = {
Lord_of_the_Rings: 4,
Harry_Potter: 4,
Jurassic_Park: 3
}
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

case choice
when "add"
puts "What movie would you like to add?"
title = gets.chomp
if movies[title.to_sym]==nil?

puts "What's the movie 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 "Which movie would you like to update?"
title = gets.chomp
if movies[title]==nil?
puts "#{title} is not stored in the hash."
else
puts "Please type in the new rating for #{title}:"
new_rating = gets.chomp
movies[title.to_sym] = new_rating.to_i
end

when "display"
movies.each { |movie,rating| puts " #{movie}: #{rating}. "}

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

Why doesn't the code work?


#2

check the exact spacing


#3

Still gives me this error: Oops, try again. Make sure to test your program by choosing 'display'.


#4

Not really much of a mistake on your end, but I'd assume taking the full stop out at the end of the code should do it.


#5

replace if movies[title.to_sym]==nil? with if movies[title.to_sym].nil?


#6

for the display part I used
when 'display'
movies.each do |movie, rating|
puts "#{movie}: #{rating}"
end


#7

I'm having a similar problem.
when 'display'
movies.each do |movie, rating|
puts "#{movie}: #{rating}"
end

Even though it displays all the titles, I keep getting a message saying . It looks like your 'puts' doesn't include back to the future: 10. (which is my first movie). Not sure where to go from here. I think my code is right?


#8

did you test it?
If you didn't, you should test it out.


#9

i dont know how it help couse my code look just like yours, but ive copied/paste yours and got a green light..
weird....


#10

my issue was I had my do after |movie, rating| instead of before...

when "idiot"
puts "facepalm"


#11

did u fix it ? i have he same problem but i cant find the solution!


#12

I dont see any problem in your code .... try checking for all correct spelling in the hash.


#13

Same here, my code looked exactly the same but only worked out when I copied/pasted the above one...


#14

movies = {
point_break: 4,
}
puts "What do you want to do?"
choice = gets.chomp

case choice
when "add"
puts "Please enter a movie title"
title = gets.chomp
if movies[title.to_sym] = nil
title = title.to_sym
else
puts "We already have that movie!"
end
puts "Please give a rating from 1 to 4."
rating = gets.chomp
rating = rating.to_i
puts "#{title} has been added with a rating of #{rating}"
movies [title]= rating

when "update"
puts "What title do you want to update"
if movies[title] = nil
puts "There is no movie to update, silly!"
else
puts "What is the new rating to assign?"
rating = gets.chomp
rating = rating.to_i
end
puts "#{title} has been given a new rating of #{rating}"
when "display"
puts movies do |movie, rating|
puts "#{movie}: #{rating}"
end
when "delete"
puts "Deleted!"
else
puts "Error!"
end

My code displays point_break and its rating of 4. I am still not able to move forward. Any suggestions?


#15

I also have the same problem, but the first movie in my hash was indeed displayed in the window, did you find how to fix it?


#16

Your puts statement "#{title}: #{rating}." should not include the period '.'

puts "#{title}: #{rating}"

will allow your movie to be printed exactly as requested by Codecademy.


#17

same problem, any answer?!


#18

The code checker is very sensitive, I left a space between #{movie} and : should have been #{movie}:


#19

I have the same problem. the results looks correct but it still shows me an error!


#20

Would just confirm that the code checker is very sensitive. I put “Update” with a capital “U” and that was the reason why it wouldn’t let me pass. Once I changed the code to be while “update”, it worked.
I know it is not an answer to all the issues.