12.4 Prompting: Redux


#1

movies = {
"Pixels" => "4.5"
}

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's the movie title"
title = gets.chomp
puts "What's the movie rating?"
rating = gets.chomp
puts "#{title} has been added with a rating of #{rating}."

when "update"
puts "Updated!"
when "display"
puts "Displayed!"
when "delete"
puts "Deleted!"
else
puts "Error!"
end

Whats a movie hash?


#2

HI then you should add the movie and the rating you input in the array movies like that

movies[title] = rating

inside the when "add"


#3

Oh thanks so much! Works now :slight_smile:


#4

Ive been trying something similar but keep hearing 'Oops, try again. It looks like you didn't add to the movies hash!'

can you spot the issue?

movies = {
Godzilla: 4,
Titanic: 1,
Inception: 2
}
puts "Enter a choice ('add', 'update', 'display', 'delete'):"
choice = gets.chomp.downcase

case choice
when "add"
puts "Enter the movie title you would like to add:"
title = gets.chomp.downcase
puts "tell me your rating out of 5?"
rating = gets.chomp
movies[title] = rating
puts "#{title}, has been added with a rating of #{rating}."

when "update"
puts "Updated!"
when "display"
puts "Movies!"
when "delete"
puts "Deleted!"
else
puts "Error!"
end


#5

Hi when you Save & submite the code you should type on the console add then type the name of the movie and its rating.


#6

Oh! Thats brilliant.
Thanks!


#7

I was also having trouble with the result even though the code was correct. Turns out it does matter what you put in the console. Thanks for this.