Code review!


#1


A Night at the Movies

Made the code more interactive, to be able to change the name and rating more efficiently.


Replace this line with your code. 

movies = {
    '300' => 5,
    'ocean twelve' => 4,
    'ocean thirteen' => 4.5
}

puts "What option do you want to select? Add, update, display or delete?"
choice = gets.chomp
choice.downcase

case choice
when 'add'
puts "what's the title?"
title = gets.chomp
if movies[title.to_s] == nil
    puts 'What is the rating?'
    rating = gets.chomp
    movies[title.to_sym] = rating.to_i
    puts 'Added!'
else
    puts "Movie already exists!"
    puts 'Not added!'
end
when 'update'
puts 'what is the title?'
title = gets.chomp
if movies[title.to_s] == nil
    puts 'No movie named '+title+' found!'
else
    puts 'What do you want to do? Change the name or rating?'
    answer = gets.chomp
    answer.downcase
    case answer
    when 'name'
    puts 'What is the new name?'
    title = gets.chomp
    movies[title.to_s]
    when 'rating'
    puts 'What is the new rating?'
    rating = gets.chomp
    movies[title.to_s] = rating.to_i
    puts 'Done!'
end
end
when "display"
movies.each do |k,v|
    puts "#{k}: #{v}"
end
when 'delete'
puts 'Which movie to delete?'
title = gets.chomp
title.downcase.to_s
if movies[title.to_s] != nil
    movies.delete(title.to_s)
    puts 'done!'
else
    puts 'Movie not found!'
end
else
    puts 'Error!'
end


#2

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