The case statement.3/10


#1



it looks like your case statement doesn't puts "Error!" when you enter unexpected input. also undefined method 'chomps' for "add/n" :string....can not figure out the problem here when all im typing is add and trying to run it. Help Help


movies = {
    'antman'=>9,
    'legend'=>6,
    'last_pitch'=>7,
    'mad_max'=>5,
    'sister_code'=>2
}

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 movie"
puts "-- type 'delete' to delete a movie"

choice = gets.chomps

case choice
when "add"
    puts "Added!"
when "update"
    puts "Updated!"
when "display"
    puts "Movies!"
when "delete"
    puts "Deleted!"
else 
    puts "Error!"
end


#2

Would you agree it is better if we can keep our hash keys matched to the proper names given to the movies?

The way to think about this in your mind is. 'GET string; TRIM' (chomp) trailing whitespace which includes line breaks ("\n").

Proper Names hash.

movies = {
    'Antman' => 9,
    'Legend' => 6,
    'Last Pitch' => 7,
    'Mad Max' => 5,
    'Sister Code' => 2
}

#3

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