Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ChantalDemissie/04c92d7b8b06b565de3848b89f02ea69 to your computer and use it in GitHub Desktop.
Save ChantalDemissie/04c92d7b8b06b565de3848b89f02ea69 to your computer and use it in GitHub Desktop.
Practiceday2.rb
#1
puts "please enter a number"
number = gets.chomp.to_i
if number > 70
puts "passing"
else number > 70
puts "not passing"
end
#2
puts 'please enter a light color'
light = gets.chomp
if light == 'green'
puts 'go'
else
puts 'stop'
end
#3
puts "please enter a number"
number = gets.chomp.to_i
if number.even?
puts "even"
else
puts "odd"
end
#4
puts "Enter a number"
number = gets.chomp.to_i
if number % 5 == 0
puts "Multiple of 5"
else
puts "Not a multiple of 5"
end
# #5
puts "Pick a number"
number = gets.chomp.to_i
if number < 10
puts "one digit"
elsif number >= 100
puts "three digits"
else
puts "two digits"
end
#6
puts "Pick a jersey number"
number = gets.chomp.to_i
if [12, 71, 80].include? number
puts "That number is retired from the seattle seahawks!"
end
#7
puts "Name a state"
state = gets.chomp
if ["Washington", "Oregon", "Idaho"].include? state
puts "This state is in the PNW"
else
puts "You should move to the PNW; it's great here!"
end
#8
size_to_ounces = {
"SHORT" => 8,
"TALL" => 12,
"GRANDE" => 16,
"VENTI" => 20,
}
puts "What size coffee do you want? [#{size_to_ounces.keys.join(', ')}]"
coffee = gets.chomp.upcase
if size_to_ounces.key?(coffee)
puts size_to_ounces[coffee]b
end
#9
puts "what is your rate of pay?"
pay_rate = gets.chomp.to_f
puts "how many hours did you work?"
hours_worked = gets.chomp.to_i
overtime_hours = hours_worked - 40
gross_pay = 0
if hours_worked > 40
gross_pay = pay_rate * hours_worked + 0.5 * pay_rate * overtime_hours
else
gross_pay = pay_rate * hours_worked
end
puts "Your gross pay is $#{gross_pay}"
#10
puts "what is your rate of pay?"
pay_rate = gets.chomp.to_f
puts "how many hours did you work?"
hours_worked = gets.chomp.to_i
overtime_hours = hours_worked - 40
gross_pay = 0
if hours_worked > 60
puts "Please see manager"
else
if hours_worked > 40
gross_pay = pay_rate * hours_worked + 0.5 * pay_rate * overtime_hours
else
gross_pay = pay_rate * hours_worked
end
puts "Your gross pay is $#{gross_pay}"
end
@shrutivanw
Copy link

Nice work!
Here are some comments:

  • Nice use of hash in exercise 8
  • Try saving this file as gistfile1.rb instead of gistfile1.txt. You've added Practiceday2.rb to the description of the gist which is not the filename.
  • Add a space after the # in comments. e.g. # 1 instead of #1.
  • How can you make it so that the user's input could be considered case-insensitive in exercise 2(green) and exercise 7 (state name)? e.g. "Green", "green", "gReen" etc. are all accepted in exercise 2. You already do this in exercise 8 (drink size).

Slack me if you have any questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment