Display error


#1



I've got stuck on this exercise:

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

My code correctly displays all of the titles, but I still get this error:
"Oops, try again. It looks like your 'puts' doesn't include Scott Pilgrim vs The World: 3.9. "
While console is:
"- display
Scott Pilgrim vs The World: 3.9
Pulp Fiction: 3.5
{:"Scott Pilgrim vs The World"=>3.9, :"Pulp Fiction"=>3.5} "

movies = {
    :"Scott Pilgrim vs The World" => 3.9,
    :"Pulp Fiction" => 3.5,
}

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."
puts "-- Type 'delete' to delete a movie."
puts

print "-"
choice = gets.chomp.downcase

case choice

when "add"
    puts "- What's the title?"
    print "-"
    title = gets.chomp.downcase
    puts "- Rate the movie. "
    print "-"
    rating = gets.chomp
    if movies[title.to_sym].nil?
        movies[title.to_sym] = rating.to_i
        puts "- Added!"
    else
        puts "- Already in list. #{title} have #{movies[title]} rating"
    end
    
when "update"
    puts "- What's the title?"
    print "-"
    title = gets.chomp.downcase
    if movies[title.to_sym].nil?
        puts "- Where is not such film, actially."
    else
        puts "- What's new rating? "
        print "-"
        new_rating = gets.chomp
        movies[title.to_sym] = new_rating.to_i
        puts "- Updated!"
    end
    
when 'display'
    movies.each do |movie, rating|
    puts "#{movie}: #{rating}"
  end
    
when "delete"
    puts "Deleted!"
    
else 
    puts "Error!"
    
end


#2

Nvm, I've got rid of "print" before "choice = gets.chomp.downcase" and it worked.


#3

For me, the issue seems to be fixed by changing the following line:

print "-"

I suspect because print doesn't add a new line after -, the interpreter might be getting confused. If you change the line to be puts "-" instead, it should work.

Sometimes being allowed to have a symbol or a string for hash keys can be confusing too.

In this case, because the hash keys are strings, the : isn't needed, so

:"Scott Pilgrim vs The World" => 3.9

can be simplified to

"Scott Pilgrim vs The World" => 3.9

Hopefully that helps, and you can move on!


#4

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