Nice Work!


#1




I want to know how to ask the user for their input (add, display, update, or delete) again after their initial choice. Any other comments on the code would be appreciated :slight_smile:


movies = {movie: 10}

puts "prompt for user input?"
choice = gets.chomp

case choice
when "add"
    puts "movie title?"
    title = gets.chomp.to_sym

    if movies[title.to_sym].nil?
    puts "rating?"
    rating = gets.chomp.to_i
   movies[title] = rating
   puts "This movie has been added"
   else 
       "This movie has ALREADY been added"
   end
   

when "update"
    puts "movie you want to update?"
    title =gets.chomp.to_sym
    if movies[title.to_sym].nil?
        puts "This movie has not been added!"
    else
        puts "rating?"
        rating = gets.chomp.to_i
       movies[title] = rating.to_i
    end
    
    
when "display"
    movies.each do |movie, rating|
        puts "#{movie}: #{rating}"
    end
    
when "delete"
    puts "Which title do you want to delete?"
    title = gets.chomp.to_sym
    if movies[title.to_sym].nil?
        puts "I can't delete something that isn't there"
    else movies.delete(title)
        puts "Title deleted!"
    end

end


#2

https://discuss.codecademy.com/t/10-nice-work-fun-add-on-to-increase-functionality/70774 I think that this user wanted to do the same thing as you.
What exactly do you want to do to it? Do you have any idea how to go about it?


#3

You're right. I do want to do the same thing as the other user. I assume I would use some sort of loop? I'm just not sure how to go about it.


#4

Yes!
I suggest using a while loop. Maybe study the other users code a little bit?
The while loop could let you do it until the user chooses the quit option.
The quit option is something that you would implement and would signal the while loop to stop.
I hope this is kind of leading you on the right path?


#6

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