Display


#1

movies = {
"MOONNIGHT" => 3,
"taken" => 4
}
puts "Do u like it"
choice = gets.chomp
case
when "add"
puts "Add a movie!"
title = gets.chomp
puts "Give the moving rating from (0-4)!"
if movies[title.to_sym].nil?
puts "How much is rating (tyoe 0 - 4)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
else
puts " the movie already exists and not add anything to the hash"
end
when "update"
puts "tell us when update"
title = gets.chomp
if movies[title.to_sym].nil?
puts "the movie is not in the hash"
else

puts "make a new rating (type 0 - 4)"
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 "Deleted!"
else
puts "Error!"
end

Oops, try again. It looks like your 'puts' doesn't include MOONNIGHT: 3.


#2

@rubyninja34657

Looks like you're prompting two time the user.


#3

Try adding choice as a argument to your case statement


#4

{:kings=>1, :rings=>2, :chings=>5}
nil
the above result is coming instead of
{kings;1,rings:2,chings:5}

my code is:-

movies = {
kings:1,
rings:2,
chings:5
}
puts "What would you like to do:add,update,display or delete?"
choice = gets.chomp

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}: #{rating}"
else
puts "That movie already exists! Its rating is #{movies[title.to_sym]}."
end
end

puts movies

case choice
when "update"
puts "Which movie to update?"
title=gets.chomp
if movies[title.to_sym].nil?
puts "error! this movie does not exist."
else
movies[title.to_sym]
puts "what rating to update? (0-5)"
text=gets.chomp
movies[title.to_sym]=rating.to_i
puts "#{title}:#{rating}"
end
case choice
when "display"
movies.each do |movies, rating|
puts "#{movies}: #{rating}"
end
end