At the Movies: 4-10; Prompting Redux


#1

I think I may be missing something, but when saving & Submitting the code and running the add process, It says that the movie I added wasn't really added to the hash.

A lot of the threads here just said to test the code which happens automatically when saving.

Here's my code:

movies = {
  Avengers: 4,
  Scott_Pilgrim: 3,
  The_Room: 1,
  Wreck_It_Ralph: 4,
  Iron_Man: 3
}

title = {}
rating = {}

puts "What would you like to do?"
choice = gets.chomp.downcase

case choice
when "add"
    puts "What did we forget?"
    title = gets.chomp
    puts "On a scale of 1-4 how would you rate it?"
    rating = gets.chomp
    puts "#{title} has been added with a rating of #{rating}."
when "update"
    puts "Updated!"
when "display"
    puts "Movies!"
when "delete"
    puts "Deleted!"
else
    puts "Error!"
end

#2

Which of these lines do you think is adding the movie to the hash?


#3

I had thought that this code would do it since the hint mentioned it:

title = {}
rating = {}

but it still doesn't work


#4
title = {}
rating = {}

This is only adding an empty hash to title and rating. By doing that you're also losing the values you just got from the user.

Your goal is to assign the content of the variables title and rating to the hash movies.

title must be a key in the hash and rating must be a value in the hash.

How do you add a key and a value inside a hash?


#5

If you mean how am I trying to get the new titles and ratings in, it would be the add part of this code:

    puts "What would you like to do?"
choice = gets.chomp.downcase

    case choice
    when "add"
        puts "What did we forget?"
        title = gets.chomp
        puts "On a scale of 1-4 how would you rate it?"
        rating = gets.chomp
        puts "#{title} has been added with a rating of #{rating}."
    when "update"
        puts "Updated!"
    when "display"
        puts "Movies!"
    when "delete"
        puts "Deleted!"
    else
        puts "Error!"
    end

#6

No, I mean what is the syntax in Ruby to add a key and a value inside a hash? That's what you need. If you don't remember, just go back to the previous exercises, it's explained in details.


#7

3 posts were split to a new topic: Oops, try again. It looks like you didn't add to the movies hash!


#12

you need to type add first really really


#13

I had the same issue.