From: Stefano Crocco Date: 2009-07-19T16:30:02+09:00 Subject: Re: genie.rb:20: syntax error, unexpected $end, expecting kEND On Sunday 19 July 2009, Alec Williams wrote: > |I get "genie.rb:20: syntax error, unexpected $end, expecting kEND" every > |I try to run the above program. It's just something I did for fun to > |impress freinds/family. I've looked over it many times, trying to mess > |with things a little to fix it, but nothing seems to work. I'm pretty > |new to the whole programming scene (I actually started yesterday) so I > |probably missed something really easy but it still baffels me. Help > |would be greatly appreciated for anyone who would be kind enough to give > |it. > | > |Attachments: > |http://www.ruby-forum.com/attachment/3884/genie.rb You are missing two end before the last one. By the way, if you want to have several "branches" in your if statement, you can use the elsif keyword instead of nested else/if. This would make your code shorter and much easier to read and debug. Here's how it would look: puts 'You see a lamp on the floor of a dusty room. Do you pick it up and rub it?' lamp=gets.chomp if lamp=='No' puts 'You turn around, and walk out of the room, always to wonder whether or not you should have rubbed it...' elsif lamp=='Yes' puts 'You walk up to the lamp and stroke it. Suddenly a genie bursts out and says "You have released me from my eternal prison. I shall now grant you one wish! State it in "I wish for (blank)" format please. State it, and it shall be done."' wish=gets.chomp if (wish== 'I wish for world peace' or wish== 'I wish for the end of world hunger') puts 'That\'s very thoughtful of you. It shall be done!' elsif (wish== 'I wish for the winning lottery ticket' or wish== 'I wish for $1,000,000') puts 'That is very selfish of you, but I must hold a promise. Your wish shall be granted.' else puts 'Your wish is my command.' end end puts 'You walk out of the dusty room, into the sunshine, awaiting a changed life as a result of your recently granted wish.' I hope this helps Stefano