Error on 8. Display


#1

Keeps giving me an error saying that "Oops, try again. It looks like your 'puts' does not include IDK: 3".

My code:

movies = Hash.new
movies[:IDK] = 3
puts "Input please:"
print ">> "
choice = gets.chomp

case choice
when "add"
    puts "Movie Title:"
    print ">> "
    title = gets.chomp.to_sym
    puts "Movie Rating:"
    print ">> "
    rating = gets.chomp.to_i
    if movies[title].nil?
        movies[title] = rating
    else
        puts "Error: Movie Already Exists"
    end
when "update"
    puts "Movie Title:"
    print ">> "
    title = gets.chomp.to_sym
    if movies[title].nil?
        puts "Error: Incorrect Input"
    else
        puts "New Rating:"
        print ">> "
        rating = gets.chomp.to_i
        movies[title] = rating
    end
when "display"
    movies.each { |movie,rating| puts "#{movie}: #{rating}" }
when "delete"
    puts "Deleted!"
when "1"
        100000.times do
        print rand(2)
        print " "
        
    end
else
    puts "Error: Incorrect Input"
end

Console Output/Input:

Input please:
>>  display
IDK: 3
{:IDK=>3}

#2

The error message is a little misleading. The problem is caused by using print ">> " instead of puts ">> ". Using print doesn't add a new line after what it prints, whereas puts does and not having the newline after >> seems to cause issues with the interpreter.

That should allow you to move forward.


#3

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