Prompting: Redux


#1

Helloo Everyone,

First time I am doing this… Can someone kindly tell me what I am doing wrong?

movies = {
  loveactually: 5,
  saw: 2,
  weddingcrashers: 4
}

puts "What would you like to do?"
puts "-- Type 'add' to add a movie."

choice = gets.chomp.downcase
case choice
when "add"
puts "What movie would you like to add?"
title = gets.chomp   
puts "What's the rating of the movie?"
rating = gets.chomp

movies = {}

movies[title] = rating

puts “Your movie rating has been added!”
    end
when'update'
puts"Updated!"
when'display'
    puts "Movies!"
when'delete'
    puts "Deleted!"
else
    puts "Error!"
end

#2

A Night at the Movies

That line just wiped out your movies hash.

Aside

For the first couple of lessons we are using the old Ruby hash syntax, so don’t manually convert your keys to symbols. Let the program do that when the time comes.

movies = {
    "Love Actually" => 5,
    "Saw" =>  2,
    "Wedding Crashers" => 4
}

Mind, it’s been awhile since I last looked at this module. Still, the above will suffice for the next couple of lessons.


#3

:see_no_evil:
thank you


#4

Sorry, I have gotten a bit further now but it is showing an error in second last line!?? I think I should take a break! LoL!

It give me the following:
(ruby):44: syntax error, unexpected end-of-input, expecting keyword_end

movies = {
loveactually: 5,
saw: 2,
weddingcrashers: 4
}
puts “What would you like to do?”
puts “-- Type ‘add’ to add a movie.”
puts “-- Type ‘update’ to update a movie.”
puts “-- Type ‘display’ to display a movie.”
puts “-- Type ‘delete’ to delete a movie.”

choice = gets.chomp.downcase
case choice
when “add”
puts “What movie would you like to add?”
title = gets.chomp
if movies[title.to_sym].nil?
puts “What’s the rating?(Type a number 0 to 5.)”
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts “Your movie rating has been added!”
end
when’update’
puts “What movie would you like to update?”
title = gets.chomp
if movies[title.to_sym].nil?
puts “Movie not found!”
else
puts “What’s the new rating?”
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts “Your movie rating has been added!”
end
when’display’
movies.each do|movie, rating|
puts “#{movie}: #{rating}”
end
when’delete’
puts “what Movie do you want to delete?”
title = gets.chomp
if movies[title.to_sym].nil?
puts “Movie not found!”
else movies.delete(title.to_sym)
puts "#{title}has been removed!"
end


#5

You’re missing the last three lines…

else
  puts "Sorry, I didn't understand you."
end

The case statement gets an optional default branch (as instructed) and an end keyword.


#6

It’s still giving me the same error message :face_with_raised_eyebrow:


#7

Please re-post your code from the above lines to the bottom.


#8

if movies[title.to_sym].nil?
puts “Movie not found”
else
movies.delete(title.to_sym)
puts “#{title} has been removed.”
end


#9

Still missing the last three lines after the if…else…end in your code above.

else
  puts "Sorry, I didn't understand you."
end

#10

I got it!! :grinning::smile::smile::smile:

I did the following:
puts “Movie not found”
else
movies.delete(title)
puts “#{title} has been removed.”
end
end

Thanks for your help!


#11

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.