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.
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.
Every if statement has to have an 'end'. Right now you've got more
if's than end's. It's because you're using this:
else
if
(with no 'end' for the if) instead of:
elsif
They're both OK, but if you use the first one, you're starting a new
if and it has to have its own end.
Compare these two:
if x
puts "x is true"
elsif y
puts "y is true"
else
puts "Neither is true"
end
if x
puts "x is true"
else
if y
puts "y is true"
else
puts "Neither is true"
end
end
You're doing something like the second, but without matching if/end.
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
···
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
i need help on this piece of code, i am new to ruby programming, i just
applied Has_one and belongs To relationship between two models but i
encountered this error while while trying to load the program. i have
tried to rollback my migrations and to migratate them again without
success.
Note the new location of the colon. The has_one thing is a method and
it takes a symbol as an argument. You can form a symbol by prefixing
some kinds of text with a colon, so :category is a symbol that is going
to be passed to the has_one method.
Take note that white space is important in Ruby as with many programming
languages, so make sure that you follow examples carefully.
Note the new location of the colon. The has_one thing is a method and it
takes a symbol as an argument. You can form a symbol by prefixing some
kinds of text with a colon, so :category is a symbol that is going to be
passed to the has_one method.
Take note that white space is important in Ruby as with many programming
languages, so make sure that you follow examples carefully.
-Jeremy
--
Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP autenticato? GRATIS solo con Email.it http://www.email.it/f
Sponsor:
Capodanno a Riccione, Pacchetto Relax: Mezza Pensione + bagno turco + solarium + massaggio. Wifi e parcheggio gratis. 2 giorni euro 199 a persona
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid978&d)-12