Display


#1


https://www.codecademy.com/en/courses/ruby-beginner-en-0i8v1/0/8?curriculum_id=5059f8619189a5000201fbcb#

console: (ruby):29: syntax error, unexpected keyword_do_block, expecting keyword_end
movies.each do |movie, rating|
^
(ruby):29: syntax error, unexpected '|', expecting '='
movies.each do |movie, rating|
^
(ruby):31: syntax error, unexpected keyword_end, expecting $end

error:
Oops, try again. Your syntax doesn't look quite right. Feel free to peek back at the first exercise if you need help!


movies = {
   Amelie: 4
}
puts "what would you like to do?"
choice = gets.chomp
choice case
when "add"
  puts "what is the title?"
  title = gets.chomp
  if movies[title.to_sym].nil?
    puts "what is the rating?"
    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
when "update"
  puts "What movie do you want to update?"
  title=gets.chomp
  if movies[title.to_sym].nil?
    puts "Movie not found!"
  else
    puts "What's the new rating? (Type a number 0 to 4.)"
    rating = gets.chomp
    movies[title.to_sym] = rating.to_i
    puts "#{title}has been updated with new rating of #{rating}."
  end
when "display"
  movies.each do |movie, rating| 
    puts "#{movie}: #{rating}"
  end
when "delete"
  puts "Deleted"
else 
  puts "Error!"
end


#2

This line jumps out. Should be, case choice.


#3

UPDATE

movies = {
   Amelie: 4
}
puts "what would you like to do?"
choice = gets.chomp
case choice
when "add"
puts "what is the title?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "what is the rating?"
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
when "update"
puts "What movie do you want to update?"
title=gets.chomp
if movies[title.to_sym].nil?
    puts "Movie not found!"
else
    puts "What's the new rating? (Type a number 0 to 4.)"
    rating = gets.chomp
    movies[title.to_sym] = rating.to_i
    puts "#{title}has been updated with new rating of #{rating}."
end
when "display"
movies[movies.each]
    puts "#{movies}: #{rating}"
when "delete"
    puts "Deleted"
else 
    puts "Error!"
end

console:
what would you like to do?
display
{:Amelie=>4}: 4
nil

error: Oops, try again. It looks like your 'puts' doesn't include Amelie: 4.


#4

what would you like to do?
 display
Amelie: 4
{:Amelie=>4}

Should be, movie (singular).


#5

I want it to display Amelie: 4 and only that


#6

Then write,

puts "#{movie}: #{rating}"

#7

undefined local variable or method `movie' for #


#8

  movies.each do |movie, rating|
    puts "#{movie}: #{rating}"
  end

#9

thanks that worked :smiley:


#10

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