Codecademy Ruby编程电影之夜

时间:2015-06-24 23:49:10

标签: ruby

我正在学习如何使用Codecademy网站编写Ruby代码。我无法让代码执行。我一直致力于"更新"案件陈述的分支。

movies = {
oceansEleven: 4.5
}

puts "Would you like to Add, Update, Display or Delete?"
choice = gets.chomp

case choice
when "add"
    print "What movie would you like to add"
    title = gets.chomp
if movies[title.to_sym].nil?
    print "How would you rate this movie? (1-5)"
    rating = gets.chomp
        movies[title.to_sym] = rating.to_i
    puts "#{title} has been added with a #{rating} rating."
else
    puts "That movie already exists! It's rating is #{rating}"
end
when "update"
    print "What movie would you like to update?
    title = gets.chomp
    if movies[title].nil?
        puts "Movie not found!"
else
    puts "What is your new rating for the movie? (1-5)"
    rating = gets.chomp
    movies[title.to_sym] = rating.to_i
    puts "#{title} has been updated with a #{rating} rating."
end
when "display"
    puts "Movies"
when "delete"
    puts "Deleted!"
else
    puts "Error!"
end

以下是我收到的错误消息:

(ruby):23: syntax error, unexpected tCONSTANT, expecting keyword_end
    puts "Movie not found!"
               ^
(ruby):25: syntax error, unexpected tCONSTANT, expecting $end
puts "What is your new rating for the movie? (1-5)"

1 个答案:

答案 0 :(得分:2)

上面三行,你忘了关闭一个字符串文字。添加"那里。

更改

 print "What movie would you like to update?

 print "What movie would you like to update?"