10. Nice Work!


#1



https://www.codecademy.com/en/courses/ruby-beginner-en-0i8v1/0/10?curriculum_id=5059f8619189a5000201fbcb


why is it when i add movie it would still ask the user to key in an input instead of displaying "Movie not found!"
and i delete movie already in database, it would still ask the user to key in an input instead of displaying "Movie not found!"


movies = {
 "Fairy Tail" => 2,
 "Gundam" => 4,
 "One Piece" => 4
}

puts "Input Your Choice add/update/display/delete :"
choice = gets.chomp.downcase

case choice
    
when "add"
  
    puts "input movie title "
    title = gets.chomp.to_sym
      
    if movies[title.to_sym].nil?
    puts"movie already exists"
end
    puts"input movie rating "
    rating = gets.chomp.to_i
    
   movies[title.to_Sym] = rating.to_i
   puts "movie was add"

when "update"
    puts "input movie title "
    title = gets.chomp.to_sym
    
if movies[title.to_sym].nil?
    puts"movie is not in the hash"
else
    puts "What's the movie's rating?"
    rating = gets.chomp.to_i
    movies[title.to_sym] = rating.to_i
    puts "movie was add"
end
 
when "display"
    movies.each {|movie, rating| puts "#{movie}: #{rating}"}
    
when 'delete'
    puts "What movie would you like to delete?"
    title = gets.chomp.to_sym
    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


#2

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