Prompting: Redux!


#1

I am having trouble with instruction: Add that movie/rating pair to the movies hash and puts a message indicating the pair was added. (No need for to_sym or to_i just yet!). Here's what I have that isn't working:

puts "Which movie would you like to see?"
choice = gets.chomp!
case choice
when "add"
puts "What movie do you want to add? "
title = gets.chomp
if movies[title.to_sym].nil?
puts "What's the rating? (Type a number 0 to 4.)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} has been added with a rating of #{rating}."
else
puts "That movie already exists! Its rating is #{movies[title.to_sym]}."
end


#2

They're asking not to use to_sym or to_i, you should try getting rid of these first.

Also, I assume you didn't publish all your code because you're missing an end and some when keywords.


#3

Error: It looks like you didn't add {} to the movies hash! - WHAT?


movies = {
double_o_seven: 10,
blacklist: 5
}

puts "name your movie?"
choice = gets.chomp.downcase

case choice
when "add"
puts "title please?"
title = gets.chomp
if movies[title].nil?
puts "rate this now"
rating = gets.chomp
movies[title] = rating
puts "#{title} has been added with a rating of #{rating}."
else
puts "That one we have. It's rating is #{movies[title]}"
end

when "update"
puts "Updated!"
when "display"
puts "Movies!"
when "delete"
puts "Deleted!"
else
puts "Error!"
end


#4

My main issue was also adding the movie/rating to my hash. With a little Q&A help, I was able to complete the program and pass through to the next lesson. I deleted all of the extraneous coding from the previous program and just followed the instructions:

movies = {
ShawshankRedemption: 4
}

puts "What would you like to do with your movie?"
choice = gets.chomp!

case choice
when "add"
puts "Please provide the title of the movie you would like to add."
title = gets.chomp!
puts "On a scale of 1 through 4, please provide the rating of the movie."
rating = gets.chomp!
puts "The movie #{title} and rating of #{rating} have been added."
movies[title] = rating
end


#5

I understood what exactly the program wants:
1. Use Symbol when make a hash
2. Later then push new movies to hash use a new code (1.9 version)

movies = Hash.new
movies = { Matrix: 10}

puts "Write down something"
choice = gets.chomp

case choice
when "add"
puts "What is the movie title?"
title = gets.chomp
puts "What is the rating of the #{title} movie?"
rating = gets.chomp
movies = { title => rating }
puts "#{title} with rating #{rating} were added to movies"
when "update"
puts "Updated!"
when "display"
puts "Movies!"
when "delete"
puts "Deleted!"
else
puts "Error!"
end


#6

So when it says "Add that movie/rating pair to the movies hash and puts a message indicating the pair was added. (No need for to_sym or to_i just yet!)"

It just means pretend that it has been added by writing that the #{title} and #{rating ahs been added. Wow. Thats confusing.


#7

lolz I'm so out of my depth... eveything makes sense about 10 steps later.