First program on Github

I put a stupid simple program on Github. It’s based on the Bridge of
Death scene in Monty Python’s Holy Grail. Feel free to take a look,
criticize, and help me do it better. I won’t become a “real” programmer
if I don’t start somewhere.

This is the code, in case you don’t want to go to Github

puts “He who would cross the Bridge of Death must answer me these
questions three, ere the other side he see!”
puts “What…is your name?”
name = gets.chomp
puts “What…is your quest?”
quest = gets.chomp

if name.downcase == “arthur”;
puts “What is the airspeed velocity of a coconut laden swallow?”
swallow = gets.chomp
if swallow.downcase == “african or european”
puts “I don’t know that! AAAAAAAAAAAAaaaaaaaaaahhhhhhh!!!”
else puts “You have been cast into the Gorge of Eternal Peril!”
end
elsif name.downcase == “lancelot”;
puts “What is your favorite color?”
colour = gets.chomp
if colour.downcase == “blue”;
puts “Alright, off you go!”
else puts “You have been cast into the Gorge of Eternal Peril!”
end
elsif name.downcase == “robin”;
puts “What is your favorite color?”
color = gets.chomp
if color.downcase != “yellow”;
puts “You have been cast into the Gorge of Eternal Peril!”
else nil
end
else puts “Your father smelt of elderberries and your mother was a
hamster! I fart in your general direction!”
end
$end

if quest.downcase != “the search for the holy grail”; puts “You are
uncultured swine!”
end

Cool, Donovan! That looks like a clever and fun approach to jumping
into control structures.

If you want to keep building on this, it could be a good candidate to
convert the if/elsif structure into a case/while structure.

Also, one thing that helped me a lot was going through bbatsov’s Ruby
Style Guide (google it, first hit). It’s a great read, and I’ve tried to
adopt it as much as possible in my code. It’s really focused on
readability, a good example of this is:

if colour.downcase == “blue”;
puts “Alright, off you go!”
else puts “You have been cast into the Gorge of Eternal Peril!”
end

becomes (see if you pick out some of the subtle differences)

if colour.downcase == ‘blue’
puts ‘Alright, off you go!’
else
puts ‘You have been cast into the Gorge of Eternal Peril!’
end

Judging by the semi-colons, do you have a background in another
language?

regards

Rob

I got syntax error without the semicolon, so I included it. If you check
out the github link, I’ve since modified the code a bit to allow for
different input with names.

I got syntax error without the semicolon

The syntax errors won’t be because of the semicolon.

Try to make the code more compact. Simple way to do so is by
having a look if you have repetitions in your code.

The various calls to:

colour = gets.chomp

This would be ideal for a method; and to ask the user for
input only once (as minimal as possible).