スクリプトを修正してケースブロックを挿入しようとしていますが、いつでもこのエラーが発生するようです。私は当初どこかで終わりを逃していたからだと思っていたが、コード全体をチェックしたところ、ちょっとチェックしたようだ。Ruby:構文エラー、予期せぬkeyword_when、入力の終了を予期します。
ワーキング(ケースを追加する前):後
def determine_grade
Console_Screen.cls #Clear the display area
#To pass the test the player must correctly retype 3 sentences
if $noRight >= 6 then
#Inform the player of the good news
print "You retyped " + $noRight.to_s + " sentence(s)" +
"correctly. "
puts "You have passed the typing test!\n\nPress Enter" +
"to continue."
else #The player has failed the test
#Inform the player of the bad news
print "You retyped " + $noRight.to_s + " sentence(s)" +
"correctly. "
puts "You have failed the typing test!\n\nPress Enter
to continue."
end
end
end
:
def determine_grade
Console_Screen.cls #Clear the display area
#To pass the test the player must correctly retype 6 sentences
case $noRight
when 9 || 10
print "You get an A!"
end
when 8
print "You get a B!"
end
when 7
print "You get a C."
end
when 6
print "You get a D."
end
when <= 5
print "You get an F."
end
else
print "Error"
end
end
end
end
任意のアイデア?
**インデント**してください!エラーが見える場合は、このような誤りをキャッチします。これを完全に解体することは大きな問題です。 2つ目は、絶対に必要でない限り、グローバル変数の使用を避けることです。 Rubyの '$ x'は単純に変数であるPHPやPerlのようなものではなく、' $ '接頭辞はグローバルを意味します。さらに、Rubyでは大文字と小文字が区別されるため、方法や変数の名前には 'no_right'(小文字はすべてアンダースコア)を使用することをお勧めします。 – tadman