2015-06-24 26 views
0

我正在學習如何使用Codecademy網站的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)" 
+2

我建議您使用語法着色編輯 - 我可以在這裏對堆棧溢出看到了問題,由於它的顏色:'打印「你想更新哪部電影?'缺少結束語。 –

回答

2

三人行,你忘了關一個字符串。添加一個「有

變化

print "What movie would you like to update? 

print "What movie would you like to update?" 
+0

這很尷尬。非常感謝你。 – cpppatrick

+0

我對你有個壞消息:你不完美。 = D(這裏是一個暗示:沒有人是因爲我們都犯錯=])。很高興我能幫上忙。乾杯。 – Alp