Created
January 4, 2019 12:58
-
-
Save Alphabetus/d996713ebcd1fb2e2ae91135911b5988 to your computer and use it in GitHub Desktop.
Commit for exercise 3.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (5+5 == 10) | |
puts "this is true" | |
else | |
puts "this is false" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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