From: Stefano Crocco Date: 2011-11-29T23:56:11+09:00 Subject: Re: What's wrong with this code? On Tuesday 29 November 2011 Kenley T. wrote > I made a program to motivate me for the last day of NaNoWriMo, but it > keeps getting 'enemy.rb:7: syntax error, unexpected kELSE, expecting > $end' > Please tell me what's wrong with the code. > Yes, it's pretty rough, because I need to make it now, but can someone > please make the code work by telling me what's wrong with it? I don't > need it to be elegant or optimized, I just need to use the program. > > Here's the program > > puts 'Enter your goal words for today' > @goal = gets.chomp.to_i > @count = 0 > @now = Time.new > @thir = Time.new + (30 * 60) > @en_points = 0 > @ur_points = 0 > While @count != @goal > if @now == @thir > @num = 500 + rand(300) > puts "#{@num}" + ' is your enemy word count. How did you fare?' > puts 'Enter how many words you typed during the thirty miinutes' > @cur = gets.chomp.to_i > @count = @count + @cur > if @cur < @num > puts 'You lost' > @en_points = @en_points + 1 > puts 'Enemy: ' + "#{@en_points}" + ' You: ' + "#{@ur_points}" > elsif @cur == @num > puts 'A tie' > puts 'Enemy: ' + "#{@en_points}" + ' You: ' + "#{@ur_points}" > else > puts 'You won' > @ur_points = @ur_points + 1 > puts 'Enemy: ' + "#{@en_points}" + ' You: ' + "#{@ur_points}" > end > else > @now = Time.new > end > end > If @en_points > @ur_points > puts 'You lost despite success.' > elsif @en_points == @ur_points > puts 'A tie, but you succeeded in writing a lot of words.' > else > puts 'Multiple victories!' > end > > -- > Posted via http://www.ruby-forum.com/. > That error means that there's an else keyword without the corresponding if. In your case, this is caused by having an If rather than if (note the different capitalization) in the seventh line from the end. Also, you use a While instead of while. Stefano