Help with 4-10 Prompting Redux


#1

This is the code that I have but I'm not really sure where I'm going wrong as I'm getting syntax errors.

movies = {
'Godfather' => 1
title = {}
title["rating"] = 1
puts 3 + title["rating"]
}
puts "Input Please"
choice = gets.chomp

case choice
when "add"
puts "Movie Title Please"
title = gets.chomp
puts "Movie Rating Please"
rating = gets.chomp
when "update"
puts "Updated"
when "display"
puts "Movies"
when "delete"
puts "Deleted"
else
puts "Error!"
end


#2

I believe the syntax error is coming from that movies is a hash, and therefore should only have key/value pairs inside of it, but all that's needed are two statements under the rating = gets.chomp line. The first one should be storing the title and rating to movies, and the second one should simply be a puts statement that announces that the movie has been added. If it helps, here is the code I used:

movies = {
    Predator: 3.5
}
puts "What would you like to do?"
choice = gets.chomp
case choice
when "add"
puts "What is the title?"
title = gets.chomp
puts "And how would you rate it? 1 to 4."
rating = gets.chomp
movies[title] = rating
puts "Added #{title} with a rating of #{rating}"
when "update"
puts "Updated!"
when "display"
puts "Movies!"
when "delete"
puts "Deleted!"
else
puts "Error!"
end

#3

movies[title] = rating works; but I don't understand how it works. Would you be able to explain why you use this line?


#4

movies is a hash, which means it's a set of keys and values, with each key corresponding to one and only one value, and vice versa.

With the instruction:

movies[title] = rating

We're telling Ruby to include in the hash movies a key title which corresponds to the value rating.

title and rating being variables which have already stored our input at this point, your input is used as key and value in the hash.


#5

I don't understand the last part of the exercise : Add movie/rating to your hash movies...puts will describe the pair you added.
my code

films = {
philadelphia: 3.5
}

puts "entrez votre choix"

choix = gets.chomp.downcase
case choix

when'ajouter'
puts "Saisissez le titre du film"
titre = gets.chomp
if titre
puts "quelle note donnez vous?"
note = gets.chomp
films[titre] = note
puts "vous avez ajouté une note de #{note} pour le film #{titre}"

end

if someone speak french that would be great


#6

I tried this but it doesn't work


#7

you have to test it out by adding a movie


#9

Je vous conseil d'éliminer le "if statement" quand vous demandez l'utilisateur de donner une note:

if titre
puts "quelle note donnez vous?"

Essayez:
puts "quelle note donnez vous?"
note = gets.chomp

Excuse mon francais!