Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Commit for exercise 3.2
# METHODS
def greeting #greeting to the user
puts "\n\n"
puts "Welcome to my first Ruby program."
puts "--" * 25
end
def userName #user identification
puts "Please enter your name:"
name = gets.chomp
puts "hello" + " " + name + " welcome!\n"
return name
end
def userAge(name)
puts "Can you tell me your age?"
age = gets.chomp
puts name
puts "So...#{name} you are #{age} years old.\nNice to meet you."
end
def bye
puts "\n\nWell that is pretty much what i can do so far, so i will just terminate.\n\nGood bye."
end
# RUN
greeting
userAge(userName)
bye
puts "--" * 25
if (5+5 == 10)
puts "this is true"
else
puts "this is false"
end
# methods
#elsif approach
def chooseElsif
puts "Do you like programming? yes or no."
choice = gets.chomp
if (choice.downcase == "yes")
puts "That\'s great"
elsif (choice.downcase == "no")
puts "That\'s too bad!"
else
puts "Incorrect answer..."
end
end
#switch approach
def chooseSwitch
puts "Do you like programming? yes, no or maybe"
choice = gets.chomp
# NOTE: Switch case has no default scenario. Use else instead.
case choice.downcase
when "yes"
puts "Cool!"
when "no"
puts "Too bad"
when "maybe"
puts "Not bad..."
else
puts "I have no default option, just an else scenario wut wut. Im special."
end
end
#run
#chooseElsif
chooseSwitch
# 3.times do
# puts "Hello"
# end
# number = 0
# while (number <= 10) do
# puts "The number is now #{number}"
# number += 1
# end
(0..10).each do |n| # Range approach. \n\ acts as index counter
puts "the number is now #{n}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment