4. Prompting:Redux!


#1

I am stuck at this exercise:
https://www.codecademy.com/en/courses/ruby-beginner-en-0i8v1/0/4?curriculum_id=5059f8619189a5000201fbcb


Code works perfectly from what I can tell but I am still getting an error:
Oops, try again. It looks like you didn't add predestination to the movies hash!

The funny thing is that this is what output of

puts movies

looks like:

{:Memento=>3, :Primer=>4, :Ishtar=>1, :predestination=>5}

movies = {
  Memento: 3,
  Primer: 4,
  Ishtar: 1
}


puts "Choose an option:" 
puts "1. ADD a movie"
puts "2. UPDATE an entry"
puts "3. DISPLAY movies"
puts "4. DELETE an entry"
choice=gets.chomp.downcase


case choice
when "add"
    puts "Movie title?"
    title=gets.chomp
    puts "Movie rating?"
    rating=gets.chomp
    movies[title.to_sym]=rating.to_i
    puts movies
    puts "Movie #{title} with a rating of #{rating} was added to the database."
when "update"
    puts "Updated!"
when "display"
    puts "Movies!"
when "delete"
    puts "Deleted!"
else
    puts "Error!"
end

#2

try this:

movies = {
Star_Wars_7: 10000000,
Star_Wars_6: 1000,
Star_Wars_3: 1000,
Star_Wars_1: -100
}
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? -100 to 1000000000."
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

please solution me if this helps


#3

I just remove the to_sym and to_i here

movies[title.to_sym]=rating.to_i

like the last part of the instruction says you don't need of it yet.


#4

Oh right! I get it.
It's not finding the movie from the hash because I converted it to a symbol and it's looking for a string. FML.


#5

Hi, bro what's wrong ?

films = {
:Zootopie => 4,
:AmericanNightmare => 3,
:Spiderman => 3,

}
puts "Quel voulez-vous faire?"
puts "-- Entrez ajouté pour ajouter un film"
puts "-- Entrez modifié pour modifier un film"
puts " -- Entrez films pour afficher un film"
puts " -- Entrez supprimé pour supprimer un film"
choix = gets.chomp.downcase

case choix
when "ajouter"
puts "Quel film voulez-vous ajouter."
titre = gets.chomp
puts "Quel note voulez-vous mettre au film (compris entre 0 et 4)."
note = gets.chomp
films[titre] = note
puts "Vous avez donné une note de #{note} au film #{film}."
when "modifier "
puts "Modifié !"
when "afficher"
puts "films !"
when "supprimer"
puts "Supprimé !"
else
puts "Erreur !"
end


#6

Hi thsi line

puts "Vous avez donné une note de #{note} au film #{film}."

this part

"..#{film}"

instead of film you should put titre


#7

thx i found the problem in my code


#8

it's still not solving it, even after removing to_sym and to_i. keeps giving an error: it looks like you didn't add to the movies hash.please advise.


#9

Hi you can post your code or create a new topic with your code. SO that we could help you


#10

Hi wizmarco! I was referring to the first code above that you solved.
movies = {
Memento: 3,
Primer: 4,
Ishtar: 1
}

puts "Choose an option:"
puts "1. ADD a movie"
puts "2. UPDATE an entry"
puts "3. DISPLAY movies"
puts "4. DELETE an entry"
choice=gets.chomp.downcase

case choice
when "add"
puts "Movie title?"
title=gets.chomp
puts "Movie rating?"
rating=gets.chomp
movies[title]=rating
puts movies
puts "Movie #{title} with a rating of #{rating} was added to the database."
when "update"
puts "Updated!"
when "display"
puts "Movies!"
when "delete"
puts "Deleted!"
else
puts "Error!"
end

What else can be wrong here to pass the lesson?thanks!


#11

When you Save & Submit Code you should type add in the console then type the name of the movie you want to add and press Enter then type the rating and press Enter


#12

Gave me a hard time, but I made it!Needed to type add, as you advised, but to press Enter after that as well to see the request for movie title.Solved, thanks a lot!