Exercice 4/10


#1

Bonjour, je ne saisi pas bien la fin de m'exercice Ajoutez votre paire film/note dans le hash films et affichez (avec puts) qui décrit la paire que vous avez ajouté. (Pour le moment vous n'avez pas besoin de to_sym ou to_i.)
Voici mon code qui ne fonctionne pas

films = {
inception: 4
philadelphia: 3
}

puts "entrez votre choix"
choix = gets.chomp
case choix

when'ajouter'
puts "Saisissez le titre du film"
titre = gets.chomp
puts "quelle note donnez vous à ce film?"
note = gets.chomp
films[titre] = note
puts "Pour le film #{titre} vous avez la note de #{note}"


#2

in English

I don't understant well the end of this exercise and my code doesn't work

movies = {
inception: 4,
philadelphia: 3
}

puts "Write your choice"
choice = gets.chomp
case choice

when'add'
puts "Write the title of the movie"
title = gets.chomp
puts "how would you rate it ?"
rating = gets.chomp
movies[title] = rating
puts "for this movie #{title} your rating is #{rating}"


#3

Which error are you getting?


#4

it says "do it again. you didn't add (anything) in the hash movies" it means title/rating i think but i did it!


#5

Yeah, it seems that your code does indeed add the movie to the hash.

However, you're using a hash with symbols even though they ask not to, maybe that's a problem to validate this exercise.

Also, when you add your movie, you're adding the key as a string, not as a symbol, you could try to use .to_sym at the end of title to see if it's detected by the exercise (or just convert all your hash to strings and keep it that way).

Try these combinations and tell me if it works.


#6

Thank you very much i did it :smile:
well i did it again and that works with .to_sym !!


#7

I was about to ask a seriously incredulous question. For all of those who didn't know please do NOT PUT A " " (Space) in ANY OF YOUR VARIABLES.. the browser will crash. (Assuming your browser is outdated as mine.)


#8

Well I think that a space in a variable name is against Ruby's naming standards, it should give you an error of this type instead of crashing:

(eval):138: undefined method `first_part_of_the_variable_name' for main:Object (NoMethodError)