No Display on Display


#1



Display - A Night at the Movies


(ruby):35: syntax error, unexpected keyword_when, expecting $end
when 'display'
^


movies =
{
Momento: 9,
Princess_Bride: 10
}

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 all movies."

choice = gets.chomp.downcase

case choice
when 'add'
puts "What is the title?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "And how would you rate it on a scale of 1-10?"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "Added #{title} with a rating of #{rating}."
else
    puts "movie already exists!"
end
when 'update'
puts "What movie would you like to update?"
title = gets.chomp
movies[title.to_sym].nil?
puts "Movie isn't found"
else
    puts "What rating would you give the movie?"
    rating = gets.chomp
    movies[title.to_sym] = rating.to_i
    puts "#{title} has been updated with a rating of #{rating}."
end
when 'display'
    movies.each do |movie, rating|
    puts "#{movie}: #{rating}" 
end


#2

Missing end for the case body (or the each method above it).


#3

It didn't work...any other ideas?


#4

This is the screen notification I received

(ruby):35: syntax error, unexpected keyword_end, expecting $end

Error notification "Your syntax doesn't look quite right."


#5

Check your structure. A little indentation will help to monitor nesting...

case choice
when 'add'
  # 
when 'update'
  # 
when 'display'
  movies.each do |movie, rating|
    puts "#{movie}: #{rating}"
  end
when 'delete'
 # 
else
  puts "I do not understand" 
end

#6

Ok, I added some spaces where required and made some additional updates and am now receiving the screen prompt for rating after entering "display", but am now receiving this notification:

"It looks like your 'puts" doesn't include Momento:9."
"syntax - undefined method 'to_sym" for nil: NilClass"

Any ideas?


#7

Please post the code you have so far.


#8

I managed to successfully complete Display - I'm now getting same errors with Delete.


#9

On the off chance that you are, don't downcase the input. Please show us your delete case.


#10

Here you go... I've played around with the "end" placements throughout the syntax, but the notifications I keep receiving state they don't like the placement of where the "end" is placed. Particularly, the "end" after the update. Thanks!

movies =
{
Momento: 9,
Princess_Bride: 10
}

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
case choice
when 'add'
puts "What is the title?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "And how would you rate it on a scale of 1-10?"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "Added #{title} with a rating of #{rating}."
else
    puts "movie already exists!"
end

when 'update'
puts "What movie would you like to update?"
title = gets.chomp
movies[title.to_sym].nil?
puts "Movie isn't found"
else
    puts "What rating would you give the movie?"
    rating = gets.chomp
    movies[title.to_sym] = rating.to_i
puts "#{title} has been updated with a rating of #{rating}
    end
when 'display'
    movies.each do |movie, rating|
puts "#{movie}: #{rating}"
end
end

when 'delete'
    puts "Which title would you like 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."
else
    puts "Sorry, I didn't understand you"
end
end

#11

The first end closes the loop, the second closes the case. Remove one.

Remove one of the end's.


#12

Didn't work...The notification I'm receiving is:

(ruby):40: syntax error, unexpected keyword_when, expecting $end
when 'delete'


#13

This if statement needs an end.


#14

Tried..it's a no go. Same error notification as before:

(ruby):40: syntax error, unexpected keyword_when, expecting $end
when 'delete'

It doesn't like my end after the end for when "display"


#15

This is what it should look like,

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

#16

That's what I have and am receiving same notification....might be a bug?


#17

Post your code one more, but please clean it up so we can see the structure plainly.

Eg.

Don't stack ends. One should have more indentation than the other to be clearly distinguishable with its associated block.

    end
  end

#18

All the "End"s have been already been changed many times and many different ways and ends in the same result.

The only thing that has worked for me thus far has been eliminating the quote on the sentence before the ends that will allow the code to be enacted and have no idea why. That's what I did on the Display exercise in order to advance.

movies =
{
Momento: 9,
Princess_Bride: 10
}

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
case choice
    when 'add'
        puts "What is the title?"
    title = gets.chomp
if movies[title.to_sym].nil?
puts "And how would you rate it on a scale of 1-10?"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "Added #{title} with a rating of #{rating}."
else
    puts "movie already exists!"
end
when 'update'
puts "What movie would you like to update?"
    title = gets.chomp
    movies[title.to_sym].nil?
    puts "Movie isn't found"
else
    puts "What rating would you give the movie?"
    rating = gets.chomp
    movies[title.to_sym] = rating.to_i
        puts "#{title} has been updated with a rating of #{rating}"
    end
when 'display'
    movies.each do |movie, rating|
    puts "#{movie}: #{rating}"
end
    when 'delete'
    puts "Which title would you like to delete?"
    title = gets.chomp
if movies[title_to_sym].nil?
    puts "Movie not found!"
     end
else
    movies.delete(title_to_sym)
    puts "#{title} has been removed."
else
    puts "Sorry, I didn't understand you"
end

#19

if movies[title_to_sym].nil?
    puts "Movie not found!"
     end
else
    movies.delete(title_to_sym)
    puts "#{title} has been removed."

should be,

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

#20

Sorry, didn't work....same notification as before:

(ruby):40: syntax error, unexpected keyword_when, expecting $end
when 'delete'

Thanks for helping.