Https://www.codecademy.com/courses/learn-ruby/lessons/a-night-at-the-movies/exercises/nice-work-1?action=resume_content_item


#1

https://www.codecademy.com/courses/learn-ruby/lessons/a-night-at-the-movies/exercises/nice-work-1?action=resume_content_item

movies = {
Anchorman: 4.5,
}

puts "What would you like to do? "

choice = gets.chomp

case choice
when “add”
puts “What movie would you like to add?”
title = gets.chomp
puts “What is your rating for this movie?”
rating = gets.chomp
if movies[title.to_sym].nil?
** movies[title.to_sym] = rating.to_i**
puts “#{title} has been added!”
else
puts “Movie already exists in hash!”
end
when “update”
puts "Input movie title: "
title = gets.chomp
if movies[title.to_sym].nil?
puts “Movie is not in hash.”
else
puts "New movie rating: "
rating = gets.chomp
movies[title.to_sym] = rating.to_i
end
when “display”
movies.each do |movie, rating|
puts “#{movie}: #{rating}”
end
when “delete”
puts "Title to be deleted: "
title = gets.chomp
if movies[title.to_sym].nil?
puts “Movie is not in hash.”
else
movies.delete(title.to_sym)
end
else
puts “Error!”
end

Here’s my code. I got through the whole lab and it said I passed everything. However, now that I finished and playing around with the lab, whenever I try to add something and then display it, it stills only shows the initial symbol inputted of Anchorman. I’m confused where I messed up and how I got everything to pass yet my program doesn’t work how it should.
Also the second part I bolded I am not sure if that is correct coding so please let me know.
Thanks in advance!


#2

The program we created above can only take one step per session and nothing is carried over. To be able to display new content we will need a loop around the command input so it repeats while our hash is still in memory.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.